我在使用Logging Block Application的时候,由于某种原因我没用FlatFileTraceListener,只能用FormattedEventLogTraceListener,但是程序执行没问题就是找不到日志文件。任何目录下都找不到。那位兄弟帮忙指点下。
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="UnknownErrors" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add source="Enterprise Library Logging" formatter="Text Formatter" log="CoCApplication" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" name="Unknown Error EventLog TraceListener"/>
      <add fileName="UnknownErrorTrace.log" header="======================" footer="----------------------------------------" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" name="Unknown Error FlatFile TraceListener"/>
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xA;Category: {category}  Priority: {priority}  EventId: {eventid}  Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}&#xA;Message: {message}&#xA;" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging" name="Text Formatter"/>
    </formatters>
    <categorySources>
      <add switchValue="All" name="UnknownErrors">
        <listeners>
          <add name="Unknown Error EventLog TraceListener"/>
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events"/>
      <notProcessed switchValue="All" name="Unprocessed Category"/>
      <errors switchValue="All" name="Logging Errors &amp; Warnings"/>
    </specialSources>
  </loggingConfiguration>
 private void button1_Click(object sender, EventArgs e)
        {
            LogEntry log = new LogEntry();
            log.EventId = 300;
            log.Message = "Sample message";
            log.Categories.Add("UnknownErrors");
            log.Priority = 5;
            Logger.Write(log);
        }