Rolling File Appender

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Rolling File Appender

neela-2
Hi Guys,
   I wanted to know whether is there any feature in NLog to role file appenders after reaching a partucular size say 500MB, i want to role the file similar to Log4Net.

If anyone know knows kindly let me know.

Regards
Neela
prasad_neela@xiotech.com
Reply | Threaded
Open this post in threaded view
|

Re: Rolling File Appender

Jarek Kowalski
Administrator
There's a new, experimental release with this function. It's called auto-archiving.

See this link:

http://www.nabble.com/New-experimental-release-of-NLog-t1490239c6167.html

Jarek
NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: Having seperate appender for particular class

neela-2
In reply to this post by neela-2
Hi Guys,
    I would like to know in my application all classes are logging into a same file.But i wanted to how to configure a seperate appneder file for particular class where i want to see messages from that class itself.

Regards
Neela
Reply | Threaded
Open this post in threaded view
|

Re: Having seperate appender for particular class

Jarek Kowalski
Administrator
Have you seen the tutorial?

<nlog>

<targets>
   <target name="f1" type="File" filename="${basedir}/f1.log" />
   <target name="f2" type="File" filename="${basedir}/f2.log" />
</targets>

<rules>
   <logger name="MyNamespace.Class" writeTo="f1" />
   <logger name="*" writeTo="f2" />
</rules>

</nlog>

Now, create logger for each class using:

private static Logger logger = LogManager.GetCurrentClassLogger();

And voila! All messages from MyNamespace.Class go to f1.log and messages from all loggers go to f2.log. Note that messages from  MyNamespace.Class are also written to f2.log. To prevent them from doing so add final="true" attribute to the first rule.

<rules>
   <logger name="MyNamespace.Class" writeTo="f1" final="true" />
   <logger name="*" writeTo="f2" />
</rules>

Jarek
NLog Blog