2009-11-17 67 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

相關問題