0

Is there any way I can use Microsoft.Diagnostic.Tracing.EventSource package or any other .NET built in types to implement a back up logic for logging?

I have used an EventSession that directs all logs to an .ETL file but there are two problems with this:

  • The most important one is that, from what I understand, the logs are actually being written to the file when the processing stops. But what happens if the machine shuts down or the processor process gets killed? From my tests the logs are lost.

  • The second problem is less important and it's just that it would be more convenient for my solution to be able to read from the file as logs are coming in.

Basically I would like to have a file buffer for my logs and I was wondering if there's some built in implementation especially for this.

1 Answers1

1
  • Yes, EventSource's WriteEvent methods are not blocking, so they do not guarantee that logs actually have been saved.
  • And yes, you cannot read ETL files while they are in use.

ETW is not the option for you in this case, you could use common TraceSource (with two listeners, one is configured to do auto-flush and another one is ETW adaptor, which you could listen to through a real-time ETW session) or log4net (you could choose appender that works for your case).