Writing to a new log file each day with TraceSource
Posted
by
Cipher
on Stack Overflow
See other posts from Stack Overflow
or by Cipher
Published on 2012-06-04T16:37:39Z
Indexed on
2012/06/04
16:40 UTC
Read the original article
Hit count: 233
c#
I am using a logger in my application to write to files. The source, switch and listeners have been defined in the app.config file as follows:
<system.diagnostics>
<sources>
<source name="LoggerApp" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="myListener.log" />
</listeners>
</source>
</sources>
<switches>
<add name="sourceSwitch" value="Information" />
</switches>
</system.diagnostics>
Inside, my .cs code, I use the logger as follows:
private static TraceSource logger = new TraceSource("LoggerApp");
logger.TraceEvent(TraceEventType.Information, 1, "{0} : Started the application", DateTime.Now);
What would I have to do to create a new log file each day instead of writing to the same log file every time?
© Stack Overflow or respective owner