0

.NET 4.5 System.Diagnostic.Tracing.EventSource で問題が発生しています。完全な EventSource 実装は、この投稿の最後にあります。

この EventSource のリスナーを作成すると、イベントを受信しません。すべてのヒント、または質問をいただければ幸いです。

edit1: - Microsoft.Practices.EnterpriseLibrary.SemanticLogging.ObservableLog を試しました -> 行きません。- リスナーの EventLevel を verbose に設定します。- PerfView.exe を使用してイベントをキャプチャできます

リスナーをアクティブにする方法:

_sink = new SignalRListener();
_sink.EnableEvents(GatewayEvent.Log, EventLevel.Verbose);

私の聞き手:

internal class SignalRListener : EventListener
{
    protected override void OnEventWritten(EventWrittenEventArgs eventData)
    {
        CommandAndControlHub.SentEventEntry(eventData);

    }
}

イベント ソース:

 using System;
 //using Microsoft.Diagnostics.Tracing;
 using System.Diagnostics.Tracing;

namespace DDA.Gateway
{
[EventSource(Name = "DDA-Gateway")]
public sealed class GatewayEvent : EventSource
{
    public class Keywords
    {

        public const EventKeywords ServiceInvoked = (EventKeywords)1;
        public const EventKeywords Diagnostic = (EventKeywords)2;
        public const EventKeywords Perf = (EventKeywords)4;
    }

    public class Tasks
    {
        public const EventTask ProcessRequest = (EventTask)1;
        public const EventTask ConnectingToHub = (EventTask)2;
        public const EventTask QueryingDataInterface = (EventTask)4;
    }

    private readonly static Lazy<GatewayEvent> Instance = new Lazy<GatewayEvent>(() => new GatewayEvent());
    private GatewayEvent() 
    {
    }
    public static GatewayEvent Log { get { return Instance.Value; } }
    [Event(1001, Message = "Application Failure: {0}",
    Level = EventLevel.Critical, Keywords = Keywords.Diagnostic)]
    public void Failure(string message)
    {
        if (this.IsEnabled())
        {
            this.WriteEvent(1001, message);
        }
    }
    [Event(1002, Message = "Connecting to hub:{0}", Opcode = EventOpcode.Start,
        Task = Tasks.ConnectingToHub, Keywords = Keywords.Diagnostic | Keywords.Perf, 
        Level = EventLevel.Informational)]
    public void ConnectingToHubStart(string url)
    {
        if (this.IsEnabled())
        {
            this.WriteEvent(1002, url); 
        }
    }

    [Event(1003, Message = "Success:{0} - Elapsed time:{1}", Opcode = EventOpcode.Stop,
        Task = Tasks.ConnectingToHub, Keywords = Keywords.Diagnostic | Keywords.Perf,
        Level = EventLevel.Informational)]
    public void ConnectingToHubEnd(bool success, string elapsedTime)
    {
        if (this.IsEnabled())
        {
            this.WriteEvent(1003, success, elapsedTime); 
        }
    }
    [Event(1004, Message = "Data received:\r\n{0}", 
        Keywords=Keywords.Diagnostic | Keywords.Perf, Level=EventLevel.Verbose)]
    public void DataReceivedByHubClient(string data)
    {
        if (IsEnabled())
        {
            this.WriteEvent(1004, data); 
        }
    }
    [Event(1005, Message = "Hub client reports a slow connection.",
        Keywords = Keywords.Diagnostic | Keywords.Perf, Level = EventLevel.Warning)]
    public void ConnectionSlow()
    {
        if (IsEnabled())
        {
            this.WriteEvent(1005); 
        }
    }

    [Event(1006, Message = "Hub client reports an arror.\r\n{0}",
        Keywords = Keywords.Diagnostic | Keywords.Perf, Level = EventLevel.Warning)]
    public void HubClientEncounteredAnError(string exceptionDetails)
    {
        if (IsEnabled())
        {
            this.WriteEvent(1006, exceptionDetails); 
        }
    }

    [Event(1007, Message = "Start Processing Request {0} for: {1}.{2}", Opcode = EventOpcode.Start,
        Task = Tasks.ProcessRequest, Keywords = Keywords.Diagnostic | Keywords.Perf,
        Level = EventLevel.Verbose)]
    public void ProcessRequestStart(string reqId, string service, string method)
    {
        if (this.IsEnabled())
        {
            this.WriteEvent(1007, reqId, service, method);
        }
    }

    [Event(1008, Message = "Ended Request process. Elapsed time:", Opcode = EventOpcode.Stop,
        Task = Tasks.ProcessRequest, Keywords = Keywords.Diagnostic | Keywords.Perf,
        Level = EventLevel.Verbose)]
    public void ProcessRequestEnd(string elapsedTime)
    {
        if (this.IsEnabled())
            this.WriteEvent(1008, elapsedTime);
    }

    [Event(1009, Message = "Request sent ({0})", Opcode = EventOpcode.Send,
        Task = Tasks.ProcessRequest, Keywords = Keywords.Diagnostic | Keywords.Perf,
        Level = EventLevel.Verbose)]
    public void ProcessRequestSendResponse(string sendDetails)
    {
        if (this.IsEnabled())
            this.WriteEvent(1009, sendDetails);
    }
}

}

4

1 に答える 1