0

我有一个部署为 Windows Azure Web 角色的 WCF 服务。

我正在使用 Enterprise Library 进行异常处理,在我的本地 Development Fabric 中,似乎使用事件日志处理程序(记录到应用程序事件日志)正确处理和记录了异常。

当它在 Azure 上运行时,似乎正在应用异常策略(因为我正在观察对某些预期异常的正确处理),但没有任何内容被记录到事件日志中。

这是异常处理策略:

<add name="Entity">
  <exceptionTypes>
    <add name="All Exceptions"
         type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
         postHandlingAction="NotifyRethrow">
      <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=31bf3856ad364e35" 
             logCategory="General" 
             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>

这是日志记录配置:

 <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
   <listeners>
     <add name="Event Log Listener"
          type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" source="Enterprise Library Logging" formatter="Text Formatter"
          log="Application" 
          machineName="." 
          traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack" />
  </listeners>
  <formatters>
    <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
         template="Timestamp: {timestamp}{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="Text Formatter" />
  </formatters>
  <categorySources>
    <add switchValue="All" name="General">
      <listeners>
        <add name="Event Log Listener" />
      </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="Event Log Listener" />
      </listeners>
    </errors>
  </specialSources>
</loggingConfiguration>

知道出了什么问题吗?

4

2 回答 2

3

进行日志记录的最佳方法是使用诊断跟踪侦听器。Windows Azure 中事件日志的名称不同。要使用此企业库,您需要将事件日志侦听器更改为 Windows Azure 诊断跟踪侦听器。在我们的“将应用程序迁移到云”一书中,我们有更多关于此的信息。代码在 VS 2008 中,但您可以在 VS 2010 中打开以查看示例。在代码中,看看我们如何使用 Windows Azure 诊断跟踪侦听器设置企业库日志记录。您需要确保将日志移过来以查看信息。本书对此进行了详细介绍。

如果您想快速浏览一下,可以从我们的 codeplex 站点下载音乐应用程序该站点显示了如何将 Enterprise Library 与 Windows Azure 一起使用。这是我们正在努力升级的旧版本。

更多关于追踪这里

于 2011-05-12T18:14:19.187 回答
1

使用具有默认设置的事件日志跟踪侦听器的先决条件是确保安装了默认事件源(“企业库日志记录”)。为了安装此事件源(或任何其他自定义源)并使用此侦听器,可以使用执行 Windows PowerShell 脚本的启动任务。这些脚本安装自定义源。带有相应 PowerShell 脚本的快速入门使用此方法。

于 2013-08-14T17:33:40.177 回答