诊断,在哪里读取 Trace.TraceInformation?

Diagnostics, where to read the Trace.TraceInformation?

Trace.AutoFlush = true;
Trace.TraceInformation(string.Format("Try starting: {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName()));
Trace.Flush();

我已阅读:How to Check the Application Event Log for Errors

可是我找不到任何踪迹!我做错了什么?

Trace 可以输出到多个侦听器。

这些可以包括调试 (visual studio)、文件甚至数据库侦听器。

默认情况下,Trace 输出到 Visual Studio output window

本文介绍了如何配置文件跟踪侦听器:How to: Create and Initialize Trace Listeners

The System.Diagnostics.Debug and System.Diagnostics.Trace classes send messages to objects called listeners that receive and process these messages. One such listener, the System.Diagnostics.DefaultTraceListener, is automatically created and initialized when tracing or debugging is enabled. If you want Trace or Debug output to be directed to any additional sources, you must create and initialize additional trace listeners.

通过 app.config:

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextWriterOutput.log" />
        <remove name="Default" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

或通过代码:

Trace.Listeners.Add(new TextWriterTraceListener("TextWriterOutput.log", "myListener"));

如果你想记录到事件日志,那么你可以使用 Event Log Trace Listener