C# 日志

增加,(应用程序配置文件)App.config


<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="listener1" type="System.Diagnostics.TextWriterTraceListener" initializeData="2.txt" />
        <add name="listener2" type="System.Diagnostics.TextWriterTraceListener" initializeData="3.txt" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>


程序中:
Trace.WriteLine("asdfafasfsaf");
            Trace.Close();


缩进与非缩进:
Trace.Indent();
            Trace.Unindent();





每天输出一个日志:
System.Diagnostics.TextWriterTraceListener l = new TextWriterTraceListener(System.DateTime.Today.ToShortDateString()+"1.txt");
            Trace.Listeners.Add(l);
            Trace.WriteLine("asdfafasfsaf");
            Trace.Close();

你可能感兴趣的:(C#)