Log File Archiving Not Working

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

Log File Archiving Not Working

CBar
Version of NLog.dll in use: 1.0.0.505, NLog for .NET 2.0
config file settings:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">
  <targets>
    <target name="file" xsi:type="File"
            layout="${longdate} ${message}"
            fileName="c:\ThruputLogs\log.txt"
            archiveFileName="c:/ThruputLogs/archive/log.#.txt"
            archiveEvery="Day"
            archiveNumbering="Rolling"
            maxArchiveFiles="5"
            concurrentWrites="true"
            keepFileOpen="false"
            encoding="iso-8859-2"
            createDirs="true" />
  </targets>

  <rules>
    <logger name="*" minlevel="Debug" writeTo="file" />
  </rules>

Testing using C# code in simple EXE, running under my windows identity, I am an admin on the local machine:
            LogFactory lf = new LogFactory();
            Logger lg = lf.GetCurrentClassLogger();
            lg.Log(LogLevel.Info, @"Some Logging Test Message Text");
            MessageBox.Show("Done");

When first running, if the log file "log.txt" in the target directory does not exist, it is created, and log messages are written to it.  This works until the date changes.  Once the date changes, I expect that the existing log will be placed into the archive directory with the name "log.0.txt", or "log.1.txt", etc., and a new log.txt file will be started with new date's messages.
However, nothing is happening at all.  The archive directory does not get created, no archive files are created, nothing gets written to any log file any longer and no exceptions are thrown.  If I manually make a change in the existing log file so that it's last date modified now reads as the current date, the log messages start getting written to the file again, but still no archive.
I would appreciate any thoughts or help anyone can provide on this.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log File Archiving Not Working

Jason LaFlair
Administrator
Try changing your archiveFileName layout

From: archiveFileName="c:/ThruputLogs/archive/log.#.txt"
To: archiveFileName="c:/ThruputLogs/archive/log.{#}.txt"

Also - you might want to include a few more # to be safe.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log File Archiving Not Working

vijaypatel
Is it mandatory to add {#} in archive file name ?

Because i have checked with " exception_${date:format=yyyyMMddHHmm}.log " and it is not working, but if i change above to          " exception_${date:format=yyyyMMddHHmm}.{#}.log " it is working fine.

So please guide me what i am missing.
Thanks,
Vijay
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log File Archiving Not Working

CBar
It appears to be.
I had the same issue, and someone gave me that solution, and it resolved my problem.
I do not recall seeing that in the documentation anywhere, but apparently that is the way it works--the code needs a placeholder in the archivefilename to determine where to put the correct archive file number.

--- On Thu, 7/12/12, vijaypatel [via NLog Forum] <[hidden email]> wrote:

From: vijaypatel [via NLog Forum] <[hidden email]>
Subject: Re: Log File Archiving Not Working
To: "CBar" <[hidden email]>
Date: Thursday, July 12, 2012, 5:16 AM

Is it mandatory to add {#} in archive file name ?

Because i have checked with " exception_${date:format=yyyyMMddHHmm}.log " and it is not working, but if i change above to          " exception_${date:format=yyyyMMddHHmm}.{#}.log " it is working fine.

So please guide me what i am missing.
Thanks,
Vijay



If you reply to this email, your message will be added to the discussion below:
http://nlog-forum.1685105.n2.nabble.com/Log-File-Archiving-Not-Working-tp7577379p7577422.html
To unsubscribe from Log File Archiving Not Working, click here.
NAML
Loading...