I want to add event log tracing to my winforms application but in don't understand to much about this.
What i have done is this steps:
In my app.config
:
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.EventLogTraceListener" initializeData="MyApplication"/>
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
A basic logger class like this:
using System;
using System.Diagnostics;
namespace LogEventSample
{
public static class Logger
{
public static void Error(string message, string module)
{
WriteEntry(message, "error", module);
}
public static void Error(Exception ex, string module)
{
WriteEntry(ex.Message, "error", module);
}
public static void Warning(string message, string module)
{
WriteEntry(message, "warning", module);
}
public static void Info(string message, string module)
{
WriteEntry(message, "info", module);
}
private static void WriteEntry(string message, string type, string module)
{
Trace.WriteLine(string.Format("{0},{1},{2},{3}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), type, module, message));
}
}
}
And then, when I need a line like this:
Logger.Info("working...", "MyApp");
My doubts comes with the application lifetime. This will impact in my application performance? should i make this in a different way?
Also, how can i store more information when i'm loggin this? i do not talk about storing some exception string but to save more detailed data to show in the event viewer.