Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net WCF Service Trace Log with log file management (Rolling)

Tags:

.net

logging

wcf

I have some .Net WCF services, for these services I have configured the app.config file to log the messages sent and received in a .svclog file which is readable by "Service Trace Viewer Tool" (SvcTraceViewer.exe) . This tool renders the log files nicely clearly showing the SOAP messages being processed.

I have to use the System.Diagnostics.XmlWriterTraceListener listener to correctly format the .svclog file to be processable by the Service Trace Viewer Tool.

The problem I have is that the .svclog file becomes too large & the Service Trace Viewer Tool becomes unusable due to slow response times.

The Service Trace Viewer Tool does provide a facility to allow a portion of the log file to be opened if the file is > 40MB in size, but this is still too slow. There appears to be no facility in the app.config file to configure the .svclog to automatically create a new file each day or when the file gets to a certain size.

There is a text log listener called Microsoft.VisualBasic.Logging.FileLogTraceListener which does support a logfilecreationschedule="Daily" property which rolls the log file daily, however the resulting log file from this listener is difficult for an operation support person to use as the log entries are not well rendered and the large xml docs contribute to the confusion.

What is the best practice in this area, it looks like I may have to write a custom WCF log extension which seems like overkill just to deal with a lack of a log file roll feature in the built in System.Diagnostics.XmlWriterTraceListener log listener / appender.

I also experimented with a script to stop my application and rename the log files but this does not seem to be possible because on Windows the handle.exe and openfile utilities are unable to close a file opened over a network share so I can't rename / move the old log file if someone is browsing it over a network share. Will post a separate question about that shortly.

Thanks, Matt.

like image 441
MattG Avatar asked May 28 '12 05:05

MattG


People also ask

How do I enable tracing and message logging in WCF?

Windows Communication Foundation (WCF) does not log messages by default. To activate message logging, you must add a trace listener to the System. ServiceModel. MessageLogging trace source and set attributes for the <messagelogging> element in the configuration file.

How can I trace a WCF service call?

Tracing is not enabled by default. To activate tracing, you must create a trace listener and set a trace level other than "Off" for the selected trace source in configuration; otherwise, WCF does not generate any traces. If you do not specify a listener, tracing is automatically disabled.

How do I check my server's diagnostic trace logs?

Right-click a server. To view the trace log file, select Open Log Files > Trace File from the menu. To view the messages log file, select Open Log Files > Message Log File from the menu.


1 Answers

You can either develop yourself or use an already existing specialized XmlWriterTraceListener or use a circular tracing log mechanism.

There is a specialized implementation of the XmlWriterTraceListener that performs rolling log tracing on Codeproject:

http://www.codeproject.com/Articles/30956/A-Rolling-XmlWriterTraceListener

With circular tracing you have two files that can each store up to half of the total desired trace log data. The listener creates one file and writes to that file until it reaches the limit of half of the data size, at which point it switches to a second file. When the listener reaches the limit for the second file - it overwrites the first file with new traces.

http://msdn.microsoft.com/en-us/library/aa395205.aspx

like image 104
Sergio Vicente Avatar answered Oct 13 '22 14:10

Sergio Vicente