2

I've been trying to work with ETW in .net 4.5.

I have a WCF Service and Console App, and I want which uses EventSource to write messages, however, I'm struggling to understand how to create my own ETW (EventSource and EventListener) for log to a file (rolling file).

Any suggestions?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Kiquenet
  • 14,494
  • 35
  • 148
  • 243

2 Answers2

4

In addition to magicandre1981's answer, you should add: -

TraceEventSession _session  = new TraceEventSession(
    "yourSessionName", @"C:\yourLogFile.etl")
{ 
    CircularBufferMB = 100 //100mb rolling log file
};
_session.EnableProvider(TraceEventProviders.GetEventSourceGuidFromName(
    "Samples-EventSourceDemos-EventLog"), TraceEventLevel.Always);

This can be in the same application as you are logging from (in process), or in a completely separate application (out of process).

Community
  • 1
  • 1
Phil Lambert
  • 1,047
  • 9
  • 16
2

Install the Nuget Package of Microsoft EventSource Library

Install-Package Microsoft.Diagnostics.Tracing.EventSource -Pre 

and define the Events in a class which is derived from EventSource.

EventSourceDemo

Now use the Semantic Logging Application Block from Enterprise Library to consume Events.

Here is a video how to use it:

Introducing Semantic Logging

http://channel9.msdn.com/posts/Introducing-Semantic-Logging

magicandre1981
  • 27,895
  • 5
  • 86
  • 127