C# 企业库-配置异常处理
我在配置异常处理程序时遇到了一些问题。我想要的是将警告和以上内容记录在一个文件(errors.txt)中,并将所有内容(包括警告和错误)记录在一个名为all.txt的文件中 问题是我无法在all.txt中记录错误,我只能在errors.txt中获得一个条目和一个名为{guid}all.txt的单独文件,其中包含错误 有人能看出我做错了什么并帮助我走上正确的道路吗C# 企业库-配置异常处理,c#,frameworks,enterprise,C#,Frameworks,Enterprise,我在配置异常处理程序时遇到了一些问题。我想要的是将警告和以上内容记录在一个文件(errors.txt)中,并将所有内容(包括警告和错误)记录在一个名为all.txt的文件中 问题是我无法在all.txt中记录错误,我只能在errors.txt中获得一个条目和一个名为{guid}all.txt的单独文件,其中包含错误 有人能看出我做错了什么并帮助我走上正确的道路吗 <exceptionHandling> <exceptionPolicies> <add name="
<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库,但我没有使用ELMAH,所以我不能对此发表评论。@Jason:请指定为什么禁止企业库??我已经在我的解决方案中实现了它,它运行得非常好。免责声明:我已经很久没有使用它了,自从我发布了我的原始评论,所以这可能不再有效。我不喜欢企业库的主要原因是正确设置它的复杂性。它只是看起来像是有很多额外的配置,而不是很多的增益。您已经可以使用内置跟踪做很多事情了,如果需要的话,通常可以构建一些专门为您的项目定制的优秀抽象,而不是EntLib人员认为您应该如何使用它。不过,EntLib的一些日志记录程序可能很有用。记住ELMAH仅适用于ASP.NET,这一点很重要。