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

I have read: How to Check the Application Event Log for Errors

But I can not find any traces! What am I doing wrong?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • 1
    Can you explain why you would expect tracing to end up in the event log? Did you configure it to write there? Start by reading [MSDN: Tracing and Instrumenting Applications](https://msdn.microsoft.com/en-us/library/zs6s4h68(v=vs.110).aspx), specifically the "Output from Tracing" section. – CodeCaster Dec 23 '16 at 10:15
  • Sorry I long fixed this problem! I wish to remove this question. I copied code and configuration from another project and it is working now. – Tony_KiloPapaMikeGolf Dec 23 '16 at 12:10
  • That's not how it works, especially not once answered. See also [How can I delete my post on Stack Overflow?](http://meta.stackexchange.com/questions/25088/how-can-i-delete-my-post-on-stack-overflow). – CodeCaster Dec 23 '16 at 12:12
  • @CodeCaster : please flag this question for removal by admin. – Tony_KiloPapaMikeGolf Dec 23 '16 at 13:21

1 Answers1

9

The Trace can output to multiple listeners.

These can include debug (visual studio), file and even database listeners.

By default the Trace outputs to the Visual Studio output window.

This article describes how to configure a file trace listener: 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.

Via the 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>

Or via code:

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

If you want to log to the Event Log then you can use the Event Log Trace Listener.