EntLib 6 Logging Rolling Flat File Listener creates a separate file per new log

Topics: Logging Application Block
Sep 30, 2014 at 4:58 AM
I'm using EntLib 6 logging Rolling Flat File and it creates a separate file with a single row of log data whenever I log in my app. I'll appreciate if anyone can help me.

My configuration is as below:

<add name="Broadcast Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="Log/Broadcast/Broadcast.log" footer="" formatter="Broadcast Text Formatter"
header="" rollFileExistsBehavior="Increment" rollInterval="Day"
rollSizeKB="10240" maxArchivedFiles="10" timeStampPattern="yyyyMMdd" />

<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Message: {message}" name="Broadcast Text Formatter" />

The class where I use to log is as below (C#):
private LogWriter _logWriter;

public Logger()
{
try
{
    IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
    LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);

    _logWriter = logWriterFactory.Create();
}
catch (Exception ex)
{
    Debug.WriteLine(ex.ToString());
}
}

public void Log(Exception exception)
{
ExceptionTypes type = 
    (exception.GetType() == typeof(BroadcastException)) ? ((BroadcastException)exception).Type : ExceptionTypes.API;

try
{
    StringBuilder sb = new StringBuilder();

    sb.AppendLine(Environment.NewLine + "Logging Time: " + DateTime.Now.ToString());

    if (exception != null)
    {
        sb.AppendLine("MES Source: " + type.ToString());
        sb.AppendLine("Exception type " + exception.GetType().ToString());
        sb.AppendLine("Exception Message: " + GetExceptionMessage(exception));
        sb.AppendLine("Exception Source:\n" + GetExceptionSource(exception));
    }

    LogEntry log = new LogEntry();
    log.Message = sb.ToString();
    log.Categories.Clear();
    log.Categories.Add(type.ToString());

    _logWriter.Write(log);
}
catch (Exception ex)
{
    Debug.WriteLine(ex.ToString());
}
}