c# - 企业库 - 配置异常处理

标签 c# frameworks enterprise

我在按照我想要的方式配置异常处理程序时遇到了一些问题。我想要的是将警告及以上内容记录在一个文件 (errors.txt) 中,并将所有内容(包括警告和错误)记录在名为 all.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}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;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 &amp; Warnings" />  </specialSources></loggingConfiguration>

最佳答案

不要使用企业库。我建议使用 ELMAH它提供了更丰富的错误处理体验并且更容易配置...

关于c# - 企业库 - 配置异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2973243/

相关文章:

java - 适合发展缓慢的机构的语言

ios - 代码 "Could not launch"。仅将 "Security"报告为错误

c# - 如果实例是具有泛型参数的类的类型,请在 C# 中检查

c# - Entity Framework 自动外键填充

ios - "Could not build module ' map 套件 '"

xcode - 如何构建具有可选依赖项的 Objective C 框架

企业应用程序的集成架构最佳实践

c# - 使用 MSWord 互操作的拼写检查窗口在我的 Vista 应用程序后面打开

c# - 将事件从 C# 应用程序传递到 Java 应用程序

php - 单独使用 PHP 是否可以轻松满足我的要求,或者我是否可以从 CMS 之类的东西中受益?