This project has moved and is read-only. For the latest updates, please go here.

No log file in Windows Service when using RollingFileTraceListener & sample config.

May 26, 2014 at 11:51 PM
I've got a Windows Service that's consuming MSMQ messages and for my debug 'logging' I'm using the basic System.Diagnostics.TextWriterTraceListener. Well, as you know that doesn't do 'rolling' files, which is necessary to keep giant log files from overrunning the server's disc space.

To that end, I found your library and tried to use the "Example Config" from the RollingFileTraceListener class' help page. ( The only thing I changed was the initializeData="{ApplicationName}-{DateTime:yyyy-MM-dd}.log" attribute. I added a path to the directory within which we want the log files placed, which gave me:

Unfortunately, when I started the service back up, I didn't see the log file. The service runs (which of course is a good thing), but alas, no log file gets created.

Not sure how to even start to debug this. So.. any help appreciated!

May 27, 2014 at 12:51 PM
To diagnose, you might want to start with a working example.

Download the complete package, from, and see if the HelloLogging example works... specifically the RollingFile example. If it is working, change to use the full path that you want and confirm that works as well.

Some suggestions:
  • You do have the Essential.Diagnostics.dll available to your application, right? (Not just the config file, you need the DLL; the easiest way is nuget: Install-Package Essential.Diagnostics.Config)
  • The example config uses the TraceSource "ExampleSource"; you need to wire it up to the default or named sources you are using.
  • Check the account the Windows Service is running under has permissions to the target directory (which I presume is the same as before).
  • Check if it works with different values for initializeData
Otherwise, post the relevant config file sections here, so I can check them.

May 27, 2014 at 4:41 PM
I went to the page you linked and found that the "Complete (binaries plus examples)" download is a .nupkg file. So, I changed it to .zip and took a peek. I'm not seeing any example project. Not sure what to do here. So, I'm going to try to repro by re-creating your HelloLogging app.

Now, one thing I've noticed that makes me a bit.. nervous is this line of code in that app; static TraceSource _trace = new TraceSource("HelloProgram");

My service is simply using the Trace.Write*() methods. Am I going to have to go in and change my code to use a specific TraceSource ?

As to your questions; 1, yes, I made sure to copy the DLL into the same dir as the service's EXE, etc. (Did in fact install via NuGet).
2. Wiring up to sources; I guess I just assumed that the example config was ready to be dropped into my .config because it's sitting inside a <system.diagnostics> element. Going to have to get my head around "sources" because currently I use a very basic configuration around a TextWriterTraceListener and there is nothing about a source or sources in it.
3. I assume it's got the perms it needs because it's been writing log file(s) via my currently configured TextWriter listener.
4. Will check that out.


May 28, 2014 at 9:03 AM
The complete download should be fixed. Sorry the wrong file was there.

If you are using Trace.Write() then you are using the default source. You need to attach the listener to the source you are using. For the default (rather than a named source), use something similar to the following (note the listeners are added to <trace>, not a specific source.... the same listener can be added to multiple sources):
      <add name="rollingfile"
        type="Essential.Diagnostics.RollingFileTraceListener, Essential.Diagnostics"        
        convertWriteToEvent="true" >
    <trace autoflush="true" indentsize="0" >
        <clear />
        <add name="rollingfile" />
Note that while it will work with the default source, it is good practice to use separate sources for the major different components of your system.

Using sources provides better logging (more options), as well as allowing you to turn on/off or set the trace level differently for different components.
May 29, 2014 at 5:12 PM
This is great, thank you so much!

Now that I'm getting my head around this, I'm definitely looking into setting up separate sources in other projects.

Thanks again,
Jun 1, 2014 at 1:28 AM
Glad I could be of help.

Don't go too crazy overboard with trace sources, as you need to configure each one separately.

I generally start with only one source, and then provide additional sources when necessary, e.g. if I want to add detailed dumps of message contents I will configure a separate source for that, so maybe end up with 2-3 sources for a small system. For some general guidance, see:

You can also include some of the system defined sources in your output, by connecting them to your listener. For details see: