EDN Admin
Well-known member
Hi,
I need to log the trace in a file. The file name needs to change every day so that that particular date holds the trace data of that particular day.
Please find my coding in app.config
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; system.diagnostics<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; switches<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; TestLog<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 4<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; switches<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; trace <span style="color:Red; autoflush<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Red; indentsize<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; listeners<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Test<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Diagnostics.TextWriterTraceListener<span style="color:Black; " <span style="color:Red; initializeData<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; D:Sample ProgramsOrdinary SamplesConsoleApplication1Test Listner DataLog.txt<span style="color:Black; "<span style="color:Blue; ><span style="color:Blue; </<span style="color:#A31515; add<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; listeners<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; trace<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; system.diagnostics<span style="color:Blue; >
[/code]
In the code behind I have the following code
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; static <span style="color:Blue; class Dia
{
<span style="color:Blue; private <span style="color:Blue; static TraceSwitch TestLog = <span style="color:Blue; new TraceSwitch(<span style="color:#A31515; "TestLog", <span style="color:#A31515; "Test the data");
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; void WriData(<span style="color:Blue; string Message)
{
TraceListener tl = <span style="color:Blue; new TraceListener();
Trace.WriteLine(<span style="color:#A31515; "Write Message" + Message+DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString());
}
}
[/code]
I call this class where ever I need the trace to be written. But the problem is that for all the days only one file is created and the trace gets appended to that file only. I am not able to get trace in separate files. In order to achive that is it possible
to change the initializeData which is present in the config file in code behind and add the datetime stamp to the file name?<br/>
I do not interested in creating the file using system.IO and creating a file every day with the help of that.
View the full article
I need to log the trace in a file. The file name needs to change every day so that that particular date holds the trace data of that particular day.
Please find my coding in app.config
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; system.diagnostics<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; switches<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; TestLog<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 4<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; switches<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; trace <span style="color:Red; autoflush<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Red; indentsize<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; listeners<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Test<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Diagnostics.TextWriterTraceListener<span style="color:Black; " <span style="color:Red; initializeData<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; D:Sample ProgramsOrdinary SamplesConsoleApplication1Test Listner DataLog.txt<span style="color:Black; "<span style="color:Blue; ><span style="color:Blue; </<span style="color:#A31515; add<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; listeners<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; trace<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; system.diagnostics<span style="color:Blue; >
[/code]
In the code behind I have the following code
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; static <span style="color:Blue; class Dia
{
<span style="color:Blue; private <span style="color:Blue; static TraceSwitch TestLog = <span style="color:Blue; new TraceSwitch(<span style="color:#A31515; "TestLog", <span style="color:#A31515; "Test the data");
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; void WriData(<span style="color:Blue; string Message)
{
TraceListener tl = <span style="color:Blue; new TraceListener();
Trace.WriteLine(<span style="color:#A31515; "Write Message" + Message+DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString());
}
}
[/code]
I call this class where ever I need the trace to be written. But the problem is that for all the days only one file is created and the trace gets appended to that file only. I am not able to get trace in separate files. In order to achive that is it possible
to change the initializeData which is present in the config file in code behind and add the datetime stamp to the file name?<br/>
I do not interested in creating the file using system.IO and creating a file every day with the help of that.
View the full article