Wednesday, June 16, 2010

TraceSource

Yesterday I was trying to get the TraceSource (http://msdn.microsoft.com/en-us/library/ms228993.aspx) working in C# under mono. I have been following the example in Microsoft website, but nothing seems to work. Today, I finally manage to get the TraceSource working. It turns out that I need to include TRACE as a define symbols in the compiler option (see the image below).



After making this change, my code

TraceSource ts = new TraceSource("DefaultTraceSource");
ts.TraceEvent (TraceEventType.Error, 1, "test");


works perfectly as intended.

Another catch I found with TraceSource is that the switchName attribute in the source element seems to be got ignored. To define the switch level, it seems better to use the switchValue attribute in the source element directly.

1 comment:

deostroll said...

What about through tracing via application configuration?