2012-05-04 41 views
2

我正在使用EntLib 4.1。我想将日志条目与不同的类别关联起来。我的类别将反映各种有趣的信息,比如上下文的种类(比如“批量”或“在线”)和功能区域(比如“发票”或“订单”)。EntLib登录到类别

我已经完成了日志记录代码,但我认为我在配置中做错了事。我试图实现的是将所有条目记录到类别“批处理”中,最终记录在名为“批处理”的事件日志中,以及应用程序日志中的所有其他内容。 (我已手动此名称创建一个自定义事件日志。)

然而,记录与类别批项目,而不是得到记录到应用程序日志,每个条目包含以下序言:

 
Message: Tracing to LogSource 'Batch' failed. Processing for other sources will continue. See summary information below for more information. Should this problem persist, stop the service and check the configuration file(s) for possible error(s) in the configuration of the categories and sinks. 

EntLib配置文件:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
     <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
    </configSections> 
    <loggingConfiguration name="Logging Application Block" tracingEnabled="true" 
     defaultCategory="APPLICATION" logWarningsWhenNoCategoriesMatch="true"> 
     <listeners> 
      <add source="Project II Logger" formatter="Text Formatter" log="Batch" 
       machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="BatchListener" /> 
      <add source="Project II Logger" formatter="Text Formatter" log="Application" 
       machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       traceOutputOptions="Callstack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="DefaultListener" /> 
      <add fileName="c:\temp\trace.log" header="----------------------------------------" 
       footer="----------------------------------------" formatter="ExceptionFormatter" 
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       traceOutputOptions="Callstack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="Exception TraceListener" /> 
     </listeners> 
     <formatters> 
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;ErrorMessages: {errorMessages}" 
       type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="ExceptionFormatter" /> 
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;ErrorMessages: {errorMessages}" 
       type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="Text Formatter" /> 
     </formatters> 
     <categorySources> 
      <add switchValue="All" name="APPLICATION"> 
       <listeners> 
        <add name="DefaultListener" /> 
       </listeners> 
      </add> 
      <add switchValue="All" name="Batch"> 
       <listeners> 
        <add name="BatchListener" /> 
       </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="DefaultListener" /> 
       </listeners> 
      </errors> 
     </specialSources> 
    </loggingConfiguration> 
</configuration> 
+0

你看到在应用程序日志中的消息表明登录到批处理类别失败。它是否给你任何其他信息,如堆栈跟踪? –

+0

是的,我得到了一个堆栈跟踪。但是有(也没有理由)认为我记录的背景与这件事有任何关系,所以我没有发布。 –

回答

0

我的猜测是,您没有在该日志中创建适当的事件日志和/或事件源。

该问题似乎没有出现在配置文件中。

如果您选择从bat文件或控制台应用程序设置新日志等,请确保在管理员下运行它。

creating log and source win 7

+0

你的回答是错误的,但我会接受它。 EntLib在第一次将某些东西记录到类别中时为您创建日志和源,因此您无需这样做。但问题是相关的:我尝试使用相同的源登录到两个不同的位置。这在Windows事件日志模型中证明是非法的,所以只有非描述性的错误信息可以归咎于EntLib。 (我希望源代码反映源代码,并将其活动摘要信息记录到集中日志中,但在其他地方记录更详细的跟踪信息)不允许! –

+0

“企业库日志记录”源自动注册,但没有其他自定义来源。 – Legends