Need a Rolling XML Trace Listener - WCF/EntLib

Topics: Logging Application Block
May 8, 2009 at 4:49 PM

Hi,

Where can I find code and guidance on writing a rolling XML trace listener?  I've seen lots of folks needing this but can't find the solution.

Our WCF traces are being emitted to EntLib along with all other traces (custom, Post Sharp, etc.). Ent lib writes all our traces to an XML log file using XML Trace Listener.  We use Service Trace Viewer to correlate and view the data and it works great.

However, it does not take too long for these log files to get large, even at production level settings (Warning and above).  Expecting IT to monitor all our log files and purge them manually is not an option. We need an XML trace listener that rolls similar to the rolling text trace listener.

I did find the Circular Tracing solution at MSDN but it is WCF Specific - meaning it inherits from XML WriterTraceListener.  When I have written custom trace listeners in the past I had to inherit from CustomTraceListener. So I don't think this solution is viable.   We want the WCF traces to go through Enterprise Library so we can turn tracing on/off in one place. SystemSevice.Model.  Send the WCF traces to a circular log file obviously eliminates our integration with Enterprise library.

Thanks

Jess

 

 

 

May 11, 2009 at 7:21 AM

Have you came across this? http://www.codeproject.com/KB/WCF/RollingXmlWriterTraceList.aspx .

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

May 11, 2009 at 2:38 PM

Yes - but (I belive) Enterprise Library Custom Trace Listeners must derive from CustomTraceListener class.

This inherets from XMLWriterTraceListener - not Custom TraceListener - so when I try to reference the assembly to add the custom trace listener I get the error message saying I need to support  CustomTraceListener class.

Am I missing something?

May 11, 2009 at 4:54 PM

I've written a CustomXMLFormatter - using this article.  It seams to be working, but I am not able to open the file I generate in ServiceTrace Viewer

http://www.c-sharpcorner.com/UploadFile/jige/704172009133451PM/7.aspx

Any reason ServiceTraceViewer can't open this file?

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href=" xmlLogTransforms.xslt "?>
<!DOCTYPE MyLog [<!ENTITY LogEntries SYSTEM "favorite.log">]>

<MyLog>

<LogEntry>
  <Timestamp>5/11/2009 12:20:13 PM</Timestamp>
  <Message>Jess: Single Client Test Trace Message</Message>
  <Category>Trace</Category>
  <Priority>-1</Priority>
  <EventId>-1</EventId>
  <Severity>Information</Severity>
  <Title>Trace</Title>
  <Machine>JPRATT2-WKS</Machine>
  <AppDomain>Shell.exe</AppDomain>
  <ProcessId>616</ProcessId>
  <ProcessName>C:\ASC Team Project\ASC.PM\bin\Debug\Shell.exe</ProcessName>
  <Win32ThreadId>1648</Win32ThreadId>
  <ThreadName />
</LogEntry> 

</MyLog>

There has to be an easy way to do this

Jess

 

May 12, 2009 at 3:47 AM

I'm not familiar on what should be the schema of the files opened in Service TraceViewer but I suggest you pattern your format with that of the LogEntry generated by an XML TraceListener.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

May 12, 2009 at 12:47 PM

Hi Sarah,

Whle the idea is interesting, we can't, nor should we, invest time writing to an undefined file format. 

Is there really no simple solution for a rolling XML trace listener for Enterprise Library derived from CustomTraceListener? 

Does anyone have a answer to the question?

I need and XML Rolling Trace Listener derived from CustomTraceListener - I can't believe we are the only company in the world in need of this

Thanks

Jess

 

 

May 18, 2009 at 3:29 AM
Edited Jan 31, 2011 at 12:14 AM

[deleted, incorrect post]

May 21, 2009 at 4:59 PM

I have a RollingXMLTrace Listener (with Valian's help) that is derived from XMLTraceListener.  However, when I try to add it to our app.conf using Enterprise Library Configuration Tool I get an error reading:

"There were no types found in the assemlby that implement or inheret from the base type Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.CustomTraceListeners"

So... can I add a trace listener derived from XMLTraceListener using the tool?

Thanks

Jess

May 22, 2009 at 3:21 AM
Edited May 22, 2009 at 3:28 AM

No, you have to inherit it from the CustomTraceListener class.  The custom xml tracelistener works but the downside is you can't select that type using the config tool, you have to manually edit the configuration file.  I'm sending another version of it.  I just modify Valiant's existing code to have it inherit from the CustomTraceListener.  You can also specify the Rolling interval in the config by adding a key value entry in the Attributes property collection.  The key to use is "interval" and for the values, you can refer to the DetermineRollingInterval method of the RollingXmlListener class.  The filename is specified through the initializeData attribute of the CustomTraceListener. 

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Jun 12, 2009 at 4:48 PM

First thanks to Valiant and Sarha for helping with this. We now have a very nice Rolling XML Trace Listener.   The trick was to derive from customtrace listener (as required) and have this new class instanciate an XMLTraceListener to do the formatted XML Logging.

Is there a way to post this class so others can us if they need to?

Thanks

Jess

Jun 15, 2009 at 3:04 AM

Yes, you can sign up for the EntLibContrib project -  http://www.codeplex.com/entlibcontrib

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Jun 24, 2009 at 9:39 PM
Edited Jun 25, 2009 at 12:45 PM

Rolling XML trace listener is working great - concerned however that it is not thread safe.  Derived from Custom Trace Listener but as you remember uses an Internal Trace Listener and a streamwriter (I can send project back to you - but woudl be great to post here so other people can benefit)

Is putting the call to write and tally in a critical section sufficient or do I need to do something else?

Thanks

Jess

  

override void Write(char value){lock (StreamWriterLock)

 

{base.Write(value);

 

tally += Encoding.GetByteCount(new char{ value });

}

 

Jun 26, 2009 at 6:17 AM
Edited Jun 29, 2009 at 7:27 AM

Admittedly, thread-safety was not in my consideration when writing the tracelistener. Thread-safety is something that is hard to prove and in addition, a matter I'm not an expert.  The best way still is to test it.  I'm guessing you also need to do something with the rollinghelper since it's a global variable within the class and some of its properties are being updated (UpdateRollingInformationIfNecessary) everytime a call to TraceData is made.

 

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Jul 6, 2009 at 4:48 PM

One other question.  How do the standard Enterprise Library file based trace listeners (rolling tex file) for example, deal with concurent access.  What if I have three instances of my client application all writing to the trace listener at the same time. 

Does the trace listener implicitly lock the file?

Do I need to worry about this?

Jess

Jul 7, 2009 at 12:09 AM

Yes, it locks the file.  If you have 2 or more trace listeners trying to write to the same file at the same time,  the other one obtains the lock and the other two will create a new file having the original file's filename prefixed with guid.  If this behavior is acceptable to  you, you need not worry about it.  But if you want to have just a single file, you would have to use the Distributor Service.  You can refer to the documentation on how to use it.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Jul 24, 2009 at 9:39 AM

Hi Sarah,

I also need this rolling xml trace listener.Can you send me this project...

Jul 27, 2009 at 3:09 AM

Yes, just include your email address.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Aug 1, 2009 at 1:40 PM

Hi Sarah,

I also need this rolling xml trace listener for my current project. Can you send me this project. I have emailed entlib.support@avanade.com

Thanks!

Aug 2, 2009 at 5:54 PM

Hi,

Please mail this at himanshu2561@hotmail.com

thanks

Aug 3, 2009 at 3:33 AM

Solution sent.

Aug 24, 2009 at 4:51 PM

Hi,

I have been looking for this also for some time. Can you please mail this to codeplex@abhay.otherinbox.com also.

Thanks.

Nov 2, 2009 at 1:43 PM

Hi,

 

I've been looking for a code sample for the same thing! Could you please email me a copy of the project - preethaz@gmail.com

 

thanks!

Nov 5, 2009 at 5:31 AM

Hi p101

your email is bouncing back

Dec 1, 2009 at 1:57 PM

Hey,

Care to send me a copy also? benvanmulders@gmail.com

Much appreciated!!

Dec 2, 2009 at 12:08 AM
Edited Dec 2, 2009 at 12:11 AM

Gmail doesn't seem to accept .zip attachments.  Please provide another email ad. You need not post it here, just send us an email in entlib.support@avanade.com

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Mar 26, 2010 at 8:19 AM

Hi Sarah,

Could you please email me a copy of the project? meetamitbhatia@hotmail.com

Much appreciated!!

Mar 30, 2010 at 1:22 PM

Can I also have a copy hardywang@hotmail.com

Thanks!

Mar 16, 2011 at 8:10 AM

Hi, mrs Sarah,

Could you please email me a copy of the project? kiquenet AT gmail DOT com

Much appreciated!!

Mar 16, 2011 at 8:38 AM

I've sent it to you.  Kindly check if you'll be able to get the attachment since sometimes we're unable to send emails with .zip attachments to gmail accounts.  Take note that it is not part of the official Enterprise Library downloads.  You can check out the EntLib Extensiblity Labs on how to create custom trace listeners.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 30, 2011 at 3:25 PM

I have sent an email to support but haven't heard anything back.

Is it possible to get you to send me a copy of this xml rolling trace listener?

bball22_83@hotmail.com

Thanks!

Jul 1, 2011 at 2:51 AM

I have send you the solution file. Kindly check your mail.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Aug 8, 2011 at 1:11 PM

Hello Sarah,

Could you please email me a copy of the project ?

h.guyau@hotmail.fr

Thanks a lot !

Aug 8, 2011 at 3:25 PM

Please, too me, kiquenet AT yahoo DOT es

Aug 9, 2011 at 4:11 AM

Hi hguyau, I've already send to you the sample solution.


alhambraeidos, I'm not sure but did you mean, kiquenet@yahoo.com? Anyway, I already send it to that address. Kindly check if you received it.

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

 

Oct 4, 2011 at 3:49 AM
Edited Oct 4, 2011 at 3:49 AM

Hi Avanade Support,

I am currently using ENT LIB 5.0.
I believe the Rolling XML TraceListener solution was not included in it, correct me if I am wrong.

Could you please send me the sample and solution to my email at chijmes10@hotmail.com?

Thanks and appreciate for your help.

 

 

Oct 4, 2011 at 4:34 AM

Hi chijmes10,

Sample solution sent! Let us know if you received it.

 

Noel Angelo Bolasoc
Avanade Software and Cloud Services
Avanade, Inc.
Contact 

 

Oct 4, 2011 at 10:10 AM
AvanadeSupport wrote:

Hi chijmes10,

Sample solution sent! Let us know if you received it.

 

Noel Angelo Bolasoc
Avanade Software and Cloud Services
Avanade, Inc.
Contact 

 


Hi Noel Angelo Bolasoc,

Thank you for the sample solution. I have received it and it works.
I am using it for WCF trace listener.

I have attached my configuration below, hope that it is able to provide some help to others who are doing something similar as well.

<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="System.ServiceModel" logWarningsWhenNoCategoriesMatch="true">     

<listeners>       
<add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="." traceOutputOptions="None"/>       
<add name="XML Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.LoggingExtension.RollingXmlTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.LoggingExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bced66a48f96aae7"               listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.LoggingExtension.RollingXmlTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.LoggingExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bced66a48f96aae7"               fileName="C:\\WCF-chartingservices-errorlog.svclog" rollSizeKB="512000" timeStampPattern="yyyy-MM-dd-HHmmss" />     
</listeners>     
<formatters>       
<add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Application Domain: {appDomain}&#xA;Process Id: {processId}&#xA;Process Name: {processName}&#xA;Win32 Thread Id: {win32ThreadId}&#xA;Thread Name: {threadName}&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter"/>     
</formatters>     
<categorySources>       
<add switchValue="All" name="System.ServiceModel">         
<listeners>           
<add name="XML Trace Listener"/>         
</listeners>       
</add>       
<add switchValue="All" name="BHG">        
<listeners>           
<add name="Event Log Listener"/>         
</listeners>       
</add>     
</categorySources>     
<specialSources>       
<allEvents switchValue="All" name="All Events"/>       
<notProcessed switchValue="All" name="Unprocessed Category"/>       
<errors switchValue="All" name="Logging Errors &amp; Warnings">         
<listeners>           
<add name="Event Log Listener"/>         
</listeners>       
</errors>     
</specialSources>   
</loggingConfiguration>
 <!-- WCF Dianostics-->
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="All">
        <listeners>
          <add name="traceListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EntLibLoggingProxyTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
Oct 10, 2011 at 8:38 PM

Dear AvanadeSupport,

could you please send sample solution to this address as well: uladzimir.palkhouski at gmail.com ?

Thank you in advance.

Feb 13, 2012 at 12:01 AM

I am using this trace listener and have it configured to roll every night at midnight.  We seem to lose a chunk of data from around 8-10am to 20:08 every day.  We are using IIS 6 and have it configured to recycle our app pool at 20:05 so i'm guessing that is why we resume logging at about 20:08.  I cannot however figure out why it stops logging in the morning.  Maybe a buffer is getting full?  Any ideas what we can do?  Thanks!

Feb 13, 2012 at 3:58 AM
Edited Feb 13, 2012 at 3:59 AM

It sounds like AutoFlush might be set to false so that the data is not being flushed after being written and then your app pool is being torn down without the data being written.  Just a guess.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Feb 13, 2012 at 5:23 PM

Thanks, I will try that.

Feb 13, 2012 at 8:28 PM

Hi Avanade Support,

Could you please send me the Rolling XML TraceListener sample and solution to my email at cantafio@gmail.com?
Thanks and appreciate for your help.

Dale

 
Mar 22, 2012 at 5:07 AM

There is an updated Rolling XML Trace Listener sample posted to the Sample Projects page.  It should be functionally equivalent to the out of the box Rolling Flat File Trace Listener except that Header, Footer, and Formatter are not supported by the Rolling XML Trace Listener.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com