1

MSEL 5 对我们来说就像一个魅力,但我一直在尝试配置额外的“categorySources”,但结果总是一样的。日志条目始终使用“defaultCategory”进行,并且在日志文件中记录了以下错误“消息:类别‘AppLogGen’没有显式映射。日志条目为:”

web.config“loggingConfiguration”条目

  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="AppLog">
<listeners>
  <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    fileName="c:\LoggingTrace\trace.log" formatter="Text Formatter"
    rollFileExistsBehavior="Increment" rollInterval="Midnight" rollSizeKB="10000"
    timeStampPattern="dd-MM-yyyy" traceOutputOptions="None" filter="All" />
  <add name="Flat File Trace Listener Login" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    fileName="c:\LoggingTrace\traceLogin.log" formatter="Text Formatter Login"
    rollFileExistsBehavior="Increment" rollInterval="Midnight" rollSizeKB="10000"
    timeStampPattern="dd-MM-yyyy" traceOutputOptions="None" filter="All" />
</listeners>
<formatters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    template="Format 1:: Timestamp: {timestamp(local)}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;"
    name="Text Formatter" />
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    template="Format 2:: Timestamp: {timestamp(local)}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;"
    name="Text Formatter Login" />
</formatters>
<categorySources>
  <add switchValue="All" name="InfinityWeb">
    <listeners>
      <add name="Flat File Trace Listener" />
    </listeners>
  </add>
  <add switchValue="All" name="AppLog">
    <listeners>
      <add name="Flat File Trace Listener Login" />
    </listeners>
  </add>
  <add switchValue="All" name="AppLogGen">
    <listeners>
      <add name="Flat File Trace Listener Login" />
    </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="Flat File Trace Listener" />
    </listeners>
  </errors>
</specialSources>

代码,写入日志文件

            //logWriter.Write(message, category, priority, eventId, (TraceEventType)severity, DefaultTitle, null);
        LogEntry logEntry = new LogEntry();
        logEntry.Categories.Add("AppLogGen");
        logEntry.Message = "Override " + message;

        logWriter.Write(logEntry);

日志文件中的输出

Timestamp: 9/6/2012 1:15:23 PM

消息:“AppLogGen”类别没有显式映射。日志条目是:

时间戳:2012 年 9 月 6 日上午 7 点 45 分 23 秒

消息:为 UserId 覆盖登录成功:Admin

类别:AppLogGen

严重性:信息类别:AppLog。. . 扩展属性:

不管我做什么,日志总是使用“defaultCategory”中指定的类别源。已经在这个上花了两天时间。帮助!

4

1 回答 1

0
<allEvents switchValue="All" name="All Events" />
    <listeners>
      <add name="Flat File Trace Listener" />
    </listeners>

这些代码行有问题。“平面文件跟踪”侦听器是所有事件的默认侦听器。所以无论发生什么事件都会默认监听。您应该通过评论此侦听器来检查。

于 2016-08-11T05:44:47.023 回答