customise logging directory and remove newline in log file?

Topics: Logging Application Block
Jan 23, 2009 at 3:37 AM
Edited Jan 23, 2009 at 3:38 AM
I have 2 simple questions. Hope can find some help here:

1. How to customise rolling.log creation from root directory to different directory: "~/Logs" ?

2. In Rollling Flat File Trace Listener, I deliberately leave Footer field empty. However, newline will created during appending. Can remove the empty line ?
Thanks in advance.

Jan 23, 2009 at 6:46 AM
You can set the absolute file path or the relative path, see this thread..

Regarding the rolling flat file tracelistener, if you leave the Footer field empty, it doesn't create an empty line in place of it.  You can check it out, set it first to anything other than an emtpy string, you'll see the resulting file will still have an extra line below the footer, the same goes when you didn't specify a footer.  But notice that if you have a succeeding log below it, there would be no empty line between the 2 logs.  The next log is simply being written right below the preceding one.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Jan 23, 2009 at 8:05 AM

Thanks for your kind and quick reply. The 1st question is solved.

For the 2nd question, I try write two logs just one after another in my code. But in the rolling.log, I received the two log separated by two newline below:

2009/01/23 03:51:27 PM [Information] Test1

2009/01/23 03:51:27 PM [Information] Test2

My web.config setting extract is below:

<add fileName="Data\Logs\rolling.log" rollSizeKB="0" timeStampPattern="yyyy-MM-dd"
        rollFileExistsBehavior="Increment" rollInterval="Day" formatter="Text Formatter"
        header="" footer="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        traceOutputOptions="Timestamp" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        name="Rolling Flat File Trace Listener" />

Just wonder if is because of header and footer setting to "" ?

Jan 23, 2009 at 8:23 AM
Check the template of the formatter you used.  I think you entered a new line there.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Jan 23, 2009 at 8:31 AM

You are absolutely right.

I checked the template formatter and replace below:
<add template="{message}&#xA;&#xA;" ... 
<add template="{message}" ...

It works perfectly now. Thank you very much.