asp.net-mvcenterprise-library

Enterprise Library Logging - Remove hyphen from format


I'm using Enterprise Library Logging block in a ASP.NET MVC application. When I write the log message in a text file it always adds 2 rows of hyphens before and after the message:

----------------------------------------
[18/11/2013 03:20:53 p.m.] Update - jcardozo - Record updated
----------------------------------------

This is the formatter I'm using:

<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="[{timestamp}] {keyvalue(action)} - {keyvalue(user)} - {message}" name="Text Formatter" />

How can I remove those hyphen lines?


Solution

  • Those are actually default properties on the trace listener (I assume you are using a Flat File Trace Listener or Rolling Flat File Trace Listener). The properties can be set by using the header and footer attributes in the configuration file. However, because they are not set and are using the default values they won't actually appear in the configuration file (but they will in the configuration tool).

    So if you want to not have a header and footer set them to empty. In the config file it would look like this:

    <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        fileName="trace.log" header="" footer="" />