Adding a logging file for TraceListener

Debugging the third-party apps I maintain has become more difficult since my organization is eliminating local admin accounts, and the application’s obsolete paradigm of saving log files in application folders (i.e. Program Files) is impossible in my environment, and also complicated because I must be a remote admin to use remote debugging, and my development system does not exhibit the same behavior and runs a different operating system. The app already uses TraceListener for live debug logging, and I need to configure a listener. Since major refactoring Shall Be Avoided, a golf clap for a return to remote debugging in log files :\

Reference: http://stackoverflow.com/questions/870634/overriding-system-diagnostics-trace-writeline-to-log-to-a-file

In code:  (Trace is in System.Diagnostics)

Trace.Listeners.Add(new TextWriterTraceListener(“foo.log”));

Trace.WriteLine(“Application started.”, “MyApp”);

Trace.WriteLine(“about to do stuff…”, “MyApp”);

(do stuff)

Trace.WriteLine(“stuff is done…”, “MyApp”);

Trace.WriteLine(“Application finished.”, “MyApp”);

foreach (TraceListener listener in Trace.Listeners)
{
listener.Flush();
}

Or a modification to app.config:

<configuration>
<system.diagnostics>
<trace autoflush=”false” indentsize=”4″>
<listeners>
<add name=”fileLogger”
type=”System.Diagnostics.TextWriterTraceListener”
This is why, it is important side effects viagra to know how erectile dysfunction develops. The blood free samples levitra flows freely when diluted. There are medicines available on the discount pharmacy viagra market that provide relief to people who suffer from ED or impotence due to various causes. Moreover, some canada viagra buy studies have found that berries and citrus fruits are helpful in preventing cancer and improving cardiac health. initializeData=”LogFile.log” />
<remove name=”Default” />
</listeners>
</trace>
</system.diagnostics>
</configuration>

 

See also:

http://stackoverflow.com/questions/870634/overriding-system-diagnostics-trace-writeline-to-log-to-a-file

Create a Logger using the Trace Listener in C#

https://msdn.microsoft.com/en-us/library/sk36c28t(v=vs.110).aspx

http://stackoverflow.com/questions/27610/how-to-add-simple-tracing-in-c

http://nlog-project.org/2010/09/02/routing-system-diagnostics-trace-and-system-diagnostics-tracesource-logs-through-nlog.html

http://dickvdbrink.github.io/c%23/2015/01/09/CSharp-Logging-using-Trace-and-DebugView.html

I like the looks of this:  http://dickvdbrink.github.io/c%23/2015/01/09/CSharp-Logging-using-Trace-and-DebugView.html

NLog, log4net, and EntLib are all noted as prepackaged logging systems by http://www.thejoyofcode.com/From_zero_to_logging_with_System_Diagnostics_in_15_minutes.aspx

 

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.