1

在我的应用程序中,我将异常和警告记录到日志文件中。现在我想将这些异常和警告记录到类别中。应该有四种方法对应Critical、Error、Warning、Information等,我该怎么做呢?

<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" fileName="Vodafone.DMS.AudioRecordingAgent.log.exclude" formatter="Text Formatter" rollInterval="Hour" rollSizeKB="1048576" traceOutputOptions="DateTime"/>
    </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}&#xD;&#xA;Message: {message}{newline}&#xD;&#xA;Category: {category}{newline}&#xD;&#xA;Priority: {priority}{newline}&#xD;&#xA;EventId: {eventid}{newline}&#xD;&#xA;Severity: {severity}{newline}&#xD;&#xA;Title:{title}{newline}&#xD;&#xA;Machine: {localMachine}{newline}&#xD;&#xA;App Domain: {localAppDomain}{newline}&#xD;&#xA;ProcessId: {localProcessId}{newline}&#xD;&#xA;Process Name: {localProcessName}{newline}&#xD;&#xA;Thread Name: {threadName}{newline}&#xD;&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
        name="Text Formatter"/>
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Rolling Flat File Trace Listener"/>
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Rolling Flat File Trace Listener"/>
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="Rolling Flat File Trace Listener"/>
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Rolling Flat File Trace Listener"/>
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
LogInfo = Logger.LogInformation(1, DateTime.Now, ex.Message, string.Empty, parameterHashTable["FileName"].ToString());
4

1 回答 1

0

我通常为此使用 System.Diagnostics.EventLogEntryType。它为您提供以下枚举:

EventLogEntryType.Error;
EventLogEntryType.FailureAudit;
EventLogEntryType.Information;
EventLogEntryType.SuccessAudit;
EventLogEntryType.Warning;
于 2013-07-22T12:58:48.240 回答