4
我按照需要配置異常處理程序時遇到了一些問題。我想要的是在一個名爲all.txt的文件中將警告和上面的內容記錄在一個文件(errors.txt)和所有內容(包括警告和錯誤)中。企業庫 - 配置異常處理
問題是我無法獲取要記錄在all.txt中的錯誤,我只在errors.txt中獲得一個條目,並在裏面有一個名爲{guid} all.txt的單獨文件。
任何人都可以看到我做錯了什麼,並幫助我在正確的軌道上?
<exceptionHandling> <exceptionPolicies>
<add name="Default">
<exceptionTypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="None">
<exceptionHandlers>
<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
logCategory="Errors" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="0" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add> </exceptionPolicies></exceptionHandling>
<loggingConfiguration name="" tracingEnabled="false" defaultCategory="All" evertImpersonation="false"> <listeners>
<add name="All Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
fileName="Logs\All.txt" footer="" formatter="All Formatter"
header="" rollInterval="Day" maxArchivedFiles="7" />
<add name="Errors Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
fileName="Logs\Errors.txt" formatter="Errors formatter" rollInterval="Day"
maxArchivedFiles="7" filter="Warning" /> </listeners> <formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
template="{timestamp(local:dd.MM.yyyy hh:mm:ss.fff)} - {severity} - {message}"
name="All Formatter" />
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
template="Timestamp: {timestamp(local:dd.MM.yyyy hh:mm:ss.fff)}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties: {dictionary({key} - {value}{newline})}"
name="Errors formatter" /> </formatters> <logFilters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
enabled="true" name="Logging Enabled Filter" /> </logFilters> <categorySources>
<add switchValue="All" name="All">
<listeners>
<add name="All Listener" />
</listeners>
</add>
<add switchValue="Warning" name="Errors">
<listeners>
<add name="Errors Listener" />
<add name="All Listener" />
</listeners>
</add> </categorySources> <specialSources>
<allEvents switchValue="Off" name="All Events" />
<notProcessed switchValue="Off" name="Unprocessed Category" />
<errors switchValue="Off" name="Logging Errors & Warnings" /> </specialSources></loggingConfiguration>
+1投票表示不使用Enterpise Library,但我沒有使用ELMAH,所以我不能關於這個的評論。 – 2011-06-27 00:33:09
@Jason:請說明爲什麼你禁止企業庫?我已經在我的解決方案中實現了它,它的工作原理相當不錯.. – 2012-11-01 12:28:52
免責聲明:自從我使用它並且發佈我的原始評論以來,這已經很長時間了,所以這可能不再有效。我不喜歡企業圖書館的主要原因是由於正確設置它的複雜性。它看起來像很多額外的配置,沒有太多的收穫。你已經可以用內置跟蹤做很多事情,如果你需要一般可以爲你的項目建立一些專門定製的好抽象,而不是EntLib人們認爲你應該使用它。一些EntLib的記錄器雖然可能有用。 – 2012-11-04 21:39:00