I'd like System.Diagnostics.EventSchemaTraceListener to generate an unlimited set of sequential files, so I initialised one with TraceLogRetentionOption.UnlimitedSequentialFiles. However, the trace output was written to one single file rather than multiple sequential files.
Is there any official or unofficial documentation or code sample on using this specific log retention option? And failing that, is my code below incorrect in any way?
To reduce magic configuration woo, I'll do everything in code. Here's how I think it's supposed to be initialised:
TraceSource ts = new TraceSource("My trace source", SourceLevels.All);
SourceSwitch sourceSwitch = new SourceSwitch("SourceSwitch", "Verbose");
ts.Switch = sourceSwitch;
ts.Listeners.Add(new System.Diagnostics.EventSchemaTraceListener(
"event.log", // "file name"
"eventschema", // "name"
1024, // buffer in bytes - I set this to be <= maximum file size
TraceLogRetentionOption.UnlimitedSequentialFiles,
1024); // max. file size in bytes - very small to illustrate the concept
And then I log to it a few times:
for (var i = 0; i < aFew; i++) {
ts.TraceData(
TraceEventType.Information, // trace level
100, // event ID: arbitrary integer
"some data to output");
}
I observe a single event.log file is created and contains all the expected information, but the TraceLogRetentionOption is not respected as the single file's size exceeds the maximum 1kB specified.
What am I doing wrong?
From what it looks like, the file size limit you impose is only a threshold if the size of the message being output exceeds the size that you specify. Citing the MSDN's MaximumFileSizeProperty page: