tags:

views:

64

answers:

3

Hi,

I'm using .net web config to create trace listener for debug and trace output in a .NET web app.

The problem is that if left, the log file, which always uses the same name can get massive and has actually caused me some application issues today.

I can't find a method on the net of setting a log file size limit, or a method of using a dynamic name, such as one that uses a date string as part of the name.

Does anyone know if this is possible?

So far I am using:

<system.diagnostics>
        <trace autoflush="true" indentsize="4">
            <listeners>
                <add name="CollectionLister" type="System.Diagnostics.TextWriterTraceListener" initializeData="Collections.log" />
            </listeners>
        </trace>
    </system.diagnostics>
+2  A: 

Personally, I would use a more sophisticated logging framework, like nlog

That can do the file splitting policy stuff for you.

Will Dean
+ 1 for this... I use log4net to do something similar.
NeilD
A: 

See Apache log4net

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="log.txt" />
    <appendToFile value="true" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="100KB" />
    <staticLogFileName value="true" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] 
            %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
</appender>
serhio
A: 

Like Will, I'd suggest using another logging framework.

My preference is Microsoft Enterprise Libraries's logging application blog.

Greets Flo

Florian Reischl