我正在使用Microsoft EventSource Library为我的Web应用程序实现日志记录机制。
该库提供了四个记录事件通道:"管理员","操作","调试"和"分析"。管理员和操作渠道工作正常,渠道可见,我能够记录事件。
由于某种原因,调试和分析通道不会出现在事件查看器中,如此屏幕截图所示:
您可以在下面看到我的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代码段来注册eventsource:
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"
答案 0 :(得分:3)
按default the Analytic and Debug are disabled:
默认情况下禁用分析和调试日志。启用后,他们 可以快速填写大量条目。出于这个原因,你 可能想要将它们打开一段指定的时间来收集 一些故障排除数据,然后再将其关闭。您可以 使用Windows界面或a执行此过程 命令行。
您必须manually show them in the Eventviewer options:
- 启动事件查看器。
- 点击
醇>View
菜单。如果选择Show Analytic and Debug Logs
,则分析和调试日志已可见。没有进一步的行动 需要。如果未选择Show Analytic and Debug Logs
,请选择Show
Analytic and Debug Logs
使这些日志可见。