1

Microsoft EventSource ライブラリを使用して、Web アプリケーションのログ メカニズムを実装しています。

このライブラリには、「管理」、「運用」、「デバッグ」、「分析」の 4 つのロギング イベント チャネルが用意されています。管理チャネルと運用チャネルは正常に機能しており、チャネルが表示され、イベントをログに記録できます。

次のスクリーンショットでわかるように、何らかの理由で、デバッグ チャネルと分析チャネルがイベント ビューアーに表示されません。

ここに画像の説明を入力

以下に、私の EventSource 実装を示します。さらに、コンソール テスト アプリケーションを含む完全な Visual Studio プロジェクトをここにアップロードしました。

管理者と運用のみが利用可能である理由を知っている人はいますか?

public static partial class WebAppEventSourceHandler
{
    [EventSource(Name = "Company-MyProject-WebApp")]
    private sealed class WebAppEventSource : EventSource
    {
        [Event(1, Message = "Instance: [{0}] Exception Type: [{1}] Exception Message: [{2}] Exception Stack Trace: [{3}] Inner Exception Type: [{4}] Inner Exception Message: [{5}] Inner Exception Stack Trace: [{6}]",
            Channel = EventChannel.Admin, Level = EventLevel.Critical, Version = 1)]
        internal void UnhandledException(string instance, string exceptionType, string exceptionMessage, string exceptionStackTrace,
            string innerExceptionType, string innerExceptionMessage, string innerExceptionStackTrace)
        {
            WriteEvent(1, instance, exceptionType, exceptionMessage, exceptionStackTrace, innerExceptionMessage,
                innerExceptionType, innerExceptionMessage, innerExceptionStackTrace);
        }

        [Event(2, Message = "Instance: [{0}] Controller: [{1}] Action: [{2}] Client Message: [{3}] Server Message: [{4}] Parameter: [{5}]",
            Channel = EventChannel.Admin, Level = EventLevel.Error, Version = 1)]
        internal void LogControllerActionError(string instance, string controller, string action,
            string clientSideMessage, string serverSideMessage, string parameter)
        {
            WriteEvent(2, instance, controller, action, clientSideMessage, serverSideMessage, parameter);
        }

        [Event(3, Message = "Instance: [{0}] Controller: [{1}] Action: [{2}] Client Message: [{3}] Server Message: [{4}] Parameter: [{5}]",
            Channel = EventChannel.Operational, Level = EventLevel.Warning, Version = 1)]
        internal void LogControllerActionWarning(string instance, string controller, string action,
            string clientSideMessage, string serverSideMessage, string parameter)
        {
            WriteEvent(3, instance, controller, action, clientSideMessage, serverSideMessage, parameter);
        }

        [Event(4, Message = "Instance: [{0}] Controller: [{1}] Action: [{2}] Message: [{3}] Server Parameter: [{4}]",
            Channel = EventChannel.Operational, Level = EventLevel.Informational, Version = 1)]
        internal void LogControllerActionInfo(string instance, string controller, string action,
            string message, string parameter)
        {
            WriteEvent(4, instance, controller, action, message, parameter);
        }

        [Event(5, Message = "Instance: [{0}] Controller: [{1}] Action: [{2}] Message: [{3}] Server Parameter: [{4}]",
            Channel = EventChannel.Debug, Level = EventLevel.Verbose, Version = 1)]
        internal void LogControllerActionDebug(string instance, string controller, string action,
            string message, string parameter)
        {
            WriteEvent(5, instance, controller, action, message, parameter);
        }

        [Event(6, Message = "Instance: [{0}] Controller: [{1}] Action: [{2}] Message: [{3}] Server Parameter: [{4}]",
            Channel = EventChannel.Analytic, Level = EventLevel.Verbose, Version = 1)]
        internal void LogControllerActionAnalytic(string instance, string controller, string action,
            string message, string parameter)
        {
            WriteEvent(6, instance, controller, action, message, parameter);
        }
    }
}

このコマンド スニペットを使用して、イベント ソースを登録しました。

C:\CustomEventSources>wevtutil.exe im EventSourceExample.Company-MyProject-WebApp.etwManifest.man /rf:"C:\CustomEventSources\EventSourceExample.Company-MyProject-WebApp.etwManifest.dll" /mf:"C:\CustomEventSources\ EventSourceExample.Company-MyProject-WebApp.etwManifest.dll"

4

1 に答える 1