简体   繁体   English

无法将侦听器注册到 System.Diagnostics.Tracing.EventSource

[英]Can't register listeners to System.Diagnostics.Tracing.EventSource

I have a component that is used by different applications.我有一个由不同应用程序使用的组件。 In this component we might need logging so I thought I'd use an EventSource.在这个组件中,我们可能需要日志记录,所以我想我会使用一个 EventSource。

The component is netstandard2.0, the application using the component is .NET Framework 4.6.1.组件为netstandard2.0,使用该组件的应用程序为.NET Framework 4.6.1。

This is what I have so far in my component:这是我到目前为止在我的组件中所拥有的:

public class XEvents
{
    public const int BeforeSendingRequest = 1;
    public const int AfterSendingRequest = 2;
}

[EventSource(Name = "XEventSource")]
public class XEventSource : EventSource
{
    public static XEventSource Log = new XEventSource();

    [Event(XEvents.BeforeSendingRequest, Message = "Request: {0}", Level = EventLevel.Verbose, Keywords = EventKeywords.WdiDiagnostic)]
    public void BeforeSendingRequest(string request) { if (IsEnabled()) WriteEvent(XEvents.BeforeSendingRequest, request); }

    [Event(XEvents.AfterSendingRequestToCsam, Message = "Response: {0}", Level = EventLevel.Verbose, Keywords = EventKeywords.WdiDiagnostic)]
    public void AfterSendingRequest(string response) { if (IsEnabled()) WriteEvent(XEvents.AfterSendingRequest, response); }

}

And in the application I added the following to the app.config:在应用程序中,我将以下内容添加到 app.config:

  <system.diagnostics>
    <sources>
      <source name="NamespaceOfEventSource.XEventSource" switchValue="Verbose">
        <listeners>
          <add name="XEventSourceListener" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="XEventSourceListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="X.log" traceOutputOptions="ProcessId, DateTime" />
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>

But when I run the application there is no X.log inside the bin folder.但是当我运行应用程序时,bin 文件夹中没有 X.log。 When I debug to the eventsource of the component I see that Enabled() returns false.当我调试到组件的事件源时,我看到 Enabled() 返回 false。

I suspect the listeners arent beeing bound to the EventSource.我怀疑听众没有绑定到 EventSource。 But I don't really see what I'm doing wrong.但我真的不明白我做错了什么。

Thanks in advance for any information you can give me!在此先感谢您提供给我的任何信息!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Diagnostics.Tracing.EventSource.IsEnabled如何工作? - How does System.Diagnostics.Tracing.EventSource.IsEnabled work? 如何在Microsoft.Diagnostics.Tracing.EventSource中正确定义关键字? - How to properly define Keywords in Microsoft.Diagnostics.Tracing.EventSource? Microsoft.Diagnostics.Tracing.EventSource不遵守为None启用EventListener的关键字 - Microsoft.Diagnostics.Tracing.EventSource not respecting EventListener enabled keywords for None 无法加载文件或程序集“Microsoft.Diagnostics.Tracing.EventSource - Could not load file or assembly 'Microsoft.Diagnostics.Tracing.EventSource System.Diagnostic.Tracing.EventSource-EventListener中没有事件 - System.Diagnostic.Tracing.EventSource - no events in EventListener System.Diagnostics.TraceSource中的跟踪输出格式 - Format of Tracing output in System.Diagnostics.TraceSource System.Diagnostics.Tracing与Azure网站 - System.Diagnostics.Tracing with Azure Website c#跟踪系统。诊断 - c# tracing system.diagnostics 剃刀未编译System.Diagnostics.Tracing.EventLevel - Razor not compiling System.Diagnostics.Tracing.EventLevel 可以同时使用EventLog或EventSource进行日志记录和跟踪吗? - Can I use either EventLog or EventSource for both logging and tracing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM