2009-11-17 63 views
6

我使用的是微软的企业库设置在.NET企业库记录一个“类型”(到事件日志)

其写入日志远细写一些日志,事件日志,但似乎没有设置类别在事件日志中。该类别在日志的消息正文中显示正常(如果我选择设置该日志),但事件查看器不会挑选该类别。

我在想什么?


C#源

LogEntry log = new LogEntry(); 
log.Message = "Test"; 
log.Categories.Add("Event"); 
Logger.Write(log); 

web配置

<loggingConfiguration name="Logging Application Block" tracingEnabled="true" 
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true"> 
<listeners> 
    <add source="TestLogSource" formatter="Text Formatter" log="TestLog" 
    machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
    traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
    name="Formatted EventLog TraceListener" /> 
</listeners> 
<formatters> 
    <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Severity: {severity}" 
    type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
    name="Text Formatter" /> 
</formatters> 
<categorySources> 
    <add switchValue="All" name="Events"> 
    <listeners> 
     <add name="Formatted EventLog TraceListener" /> 
    </listeners> 
    </add> 
    <add switchValue="All" name="General"> 
    <listeners> 
     <add name="Formatted EventLog TraceListener" /> 
    </listeners> 
    </add> 
</categorySources> 
<specialSources> 
    <allEvents switchValue="All" name="All Events" /> 
    <notProcessed switchValue="All" name="Unprocessed Category" /> 
    <errors switchValue="All" name="Logging Errors &amp; Warnings"> 
    <listeners> 
     <add name="Formatted EventLog TraceListener" /> 
    </listeners> 
    </errors> 
</specialSources> 

+0

'log.Categories.Add(“Event ** s **”);'? – 2009-11-17 15:47:20

+0

你的意思是你想在事件查看器中将你的记录事件放在你自己的类别下吗?或者一旦您在事件查看器中查看它,您无法看到详细信息中的类别? – curtisk 2009-11-17 16:00:02

回答

5

事件日志类别是从LogEntry类别分开且不同。所以我不认为您可以使用LogEntry类别在EventLog类别字段中显示。

从数据的角度来看,类型是不兼容的:事件日志类别很短,而LogEntry类别是一个字符串。是的,在事件查看器中它显示一个字符串,但是通过在注册表中定义的CategoryMessageFile查找该值。

如果您希望能够在事件查看器中进行一些筛选,则可以使用LogEntry.EventId属性。你可以使用任何你想要的约定来填充它。例如每个记录点的唯一事件ID,每层的事件ID,每个类的事件ID或其他约定。

作为回退,您可以在事件日志条目的描述中始终为您的类别进行查找。

1

此链接(http://drdobbs.com/184405714)包含有关如何创建类别的更多信息。

+0

有关Event Category的更多帮助链接 - http://msdn.microsoft.com/zh-cn/library/system.diagnostics.eventsourcecreationdata.categoryresourcefile.aspx – Rajes 2011-07-22 07:29:41

相关问题