Keep all the log entries for the logger "xyz" in the same file

2 messages Options
Embed this post
Permalink
Giulio Petrucci

Keep all the log entries for the logger "xyz" in the same file

Reply Threaded More More options
Print post
Permalink
Hi there,

first of all: I'm quite a newbie using NLog so my question might seem
kind of silly.
Moreover my English is not so good so... please: be merciful! :-)

I have this nlog cofig section:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <targets>
            <target name="FooLog" xsi:type="File"
                layout="${date:format=HH\:mm\:ss\:fff} ${message}
${exception:format=Type,Message,StackTrace}"
               fileName="${basedir}/Logs/${date:format=yyyy}/${date:format=MM}/${date:format=dd}/${date:format=hh}/${logger}.log"
                keepFileOpen="false" encoding="iso-8859-2"/>
        </targets>
        <rules>
            <logger name="*" minlevel="Trace" writeTo="FooLog"/>
        </rules>
    </nlog>

if my application session starts at 17:59 and goes on untill 18.02 I
have the log entries splitted into two different files:

.Logs//2009/Some-Month/Some-Day/17/xyz.log
.Logs//2009/Some-Month/Some-Day/18/xyz.log

Is there any way to make the logger write always on the same file but
without buffering the log entries?

Thanks in advance,
Giulio - Italy
--

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Nlog-list mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/nlog-list
Giulio Petrucci

Re: Keep all the log entries for the logger "xyz" in the same file

Reply Threaded More More options
Print post
Permalink
Hi there,

On Wed, Nov 4, 2009 at 5:53 PM, Giulio Petrucci
<[hidden email]> wrote:
> Hi there,
[cut]

I've been playing around with NLog and I couldn't find any way except
of configuring the Logger object not via the config file.
The resulting source code is like this:

string logName = ... ;
DateTime now = DateTime.Now;
NLog.Targets.FileTarget ft = new NLog.Targets.FileTarget();
ft.CreateDirs = true;
ft.Layout = "${date:format=HH\\:mm\\:ss\\:fff} ${message}
${exception:format=Type,Message,StackTrace}";
ft.FileName = "${basedir}/Logs/" + now.ToString("yyyy/MM/dd/HH") +
"/${logger}.log";
ft.KeepFileOpen = false;
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(ft, LogLevel.Trace);
Logger logger = LogManager.GetLogger(logName);

HTH,
Giulio
--

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Nlog-list mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/nlog-list