2

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

我已经完成了日志记录代码,但我认为我在配置中做错了什么。我想要实现的是让所有记录到“批处理”类别的条目最终都出现在名为“批处理”的事件日志中,而其他所有内容都出现在应用程序日志中。(我已经手动创建了这个名称的自定义事件日志。)

但是,具有 Batch 类别的日志条目会被记录到应用程序日志中,并且每个条目都包含以下前导码:

消息:跟踪 LogSource 'Batch' 失败。其他来源的处理将继续。有关详细信息,请参阅下面的摘要信息。如果此问题仍然存在,请停止服务并检查配置文件以查找类别和接收器配置中可能出现的错误。

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>
4

1 回答 1

0

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

问题似乎不在配置文件中。

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

创建日志和源win 7

于 2012-05-07T20:48:54.307 回答