代码之家  ›  专栏  ›  技术社区  ›  Felipe Pessoto

如何在EventType中分离企业日志文件?

  •  1
  • Felipe Pessoto  · 技术社区  · 15 年前

    我有一个日志mysite.log

    是否可以在mysite.error.log、mysite.debug.log、mysite.warning.log中自动分隔?取决于TraceEventType?

    2 回复  |  直到 15 年前
        1
  •  2
  •   Shiraz Bhaiji    15 年前

    我们这样做:

            Logger.Write("Message or exception", "Catergory");
    

    在这种情况下,类别是错误、调试或警告。

    然后在配置文件中查找错误:

    <listeners>
      <add fileName="Errors.log" footer="----------------------------------------"
        header="----------------------------------------" rollFileExistsBehavior="Overwrite"
        rollInterval="None" rollSizeKB="0" timeStampPattern="yyyy-MM-dd"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Errors" />
    </listeners>
    
    
    <categorySources>
      <add switchValue="All" name="Errors">
        <listeners>
          <add name="Errors" />
        </listeners>
      </add>
    </categorySources>
    

    您需要为每个类别执行此操作

        2
  •  0
  •   McGovernTheory    15 年前

    为此,您可以实现过滤器,或者使用不同的附加器编写它们。