I'm using system.diagnostic to log all the errors to a log file

Web.Config:

<system.diagnostics>
    <trace autoflush="true" indentsize="4">
      <listeners>
        <add name="MyListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="MyListenerLog.txt" />
        <remove name="Default" />
      </listeners>
    </trace>

  </system.diagnostics>

Code:

 private static void AddToMyListner(string message)
        {
            try
            {
                System.Diagnostics.Trace.WriteLine("Text: " +message + "," + DateTime.UtcNow);
                System.Diagnostics.Trace.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

In the Log file the first log i got was

no configuration section <common/logging> found - suppressing logging output

This log is printed only once i.e. only when I create a new log file. I'm not using Common.Logging so i was wondering what is causing this issue.

有帮助吗?

解决方案

Common.Logging is commonly integrated with tracing. If you're getting this error and you're not deliberately referencing Common.Logging then you're probably referencing some external library that uses Common.Logging and subscribes to the trace by default. If there's no configuration in place (reasonable, since you're not intending to use Common.Logging) then this would happen when Common.Logging receives a notification that something was written to the trace and doesn't know what to do about it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top