gpt4 book ai didi

c# - 为什么 channel "Debug"和 "Analytic"不适用于我的 ETW-EventSource 实现?

转载 作者:太空宇宙 更新时间:2023-11-03 23:19:48 25 4
gpt4 key购买 nike

我正在使用 Microsoft EventSource Library为我的 Web 应用程序实现日志记录机制。

该库提供了四个日志记录事件 channel :“管理”、“操作”、“调试”和“分析”。 Admin 和 Operational channel 工作正常, channel 可见,我能够记录事件。

由于某些原因,调试和分析 channel 没有出现在事件查看器中,您可以在这个屏幕截图中看到:

enter image description here

您可以在下面看到我的 EventSource 实现。此外,我还上传了完整的 Visual Studio 项目,包括控制台测试应用程序 here .

有谁知道为什么只有 Admin 和 Operational 可用?

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);
}
}
}

我使用这个 cmd 片段来注册事件源:

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"

最佳答案

通过 default the Analytic and Debug are disabled :

Analytic and Debug logs are disabled by default. When enabled, they can quickly fill with a large number of entries. For this reason, you will probably want to turn them on for a specified period to gather some troubleshooting data and then turn them off again. You can perform this procedure by using either the Windows interface or a command line.

你必须 manually show them in the Eventviewer options :

  1. Start Event Viewer.
  2. Click the View menu. If Show Analytic and Debug Logs is selected, Analytic and Debug logs are already visible. No further action is required. If Show Analytic and Debug Logs is not selected, select Show Analytic and Debug Logs to make these logs visible.

enter image description here

关于c# - 为什么 channel "Debug"和 "Analytic"不适用于我的 ETW-EventSource 实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35793953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com