Archiving problem: cannot access the file because it is being used by another process.

3 messages Options
Embed this post
Permalink
leahcimp

Archiving problem: cannot access the file because it is being used by another process.

Reply Threaded More More options
Print post
Permalink
I am trying to enable archiving, but I'm getting an internal NLog exception when NLog attempts to move the log file to my archive directory.  I am developing an ASP.NET application with VS2008.  

Here is the exception:

2009-09-11 14:58:36.2201 Error Target exception: System.IO.IOException: The process cannot access the file because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.__Error.WinIOError()
   at System.IO.File.Move(String sourceFileName, String destFileName)
   at NLog.Targets.FileTarget.SequentialArchive(String fileName, String pattern)
   at NLog.Targets.FileTarget.DoAutoArchive(String fileName, LogEventInfo ev)
   at NLog.Targets.FileTarget.Write(LogEventInfo logEvent)
   at NLog.LoggerImpl.Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)


Here is my (very basic) NLog config:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         internalLogFile="logs/log_nlogInternal.txt" >
    <targets>
        <target name="log_target_info" xsi:type="File"
                layout="${longdate} | ${callsite} | ${level} | ${message}"
                fileName="${basedir}/logs/log_info.txt"
                archiveFileName="${basedir}/logs/archive/log_info.{#####}.txt"
                archiveEvery="Minute"
                archiveNumbering="Sequence"
                concurrentWrites="false"
                keepFileOpen="false"
                />
    </targets>

    <rules>
      <logger name="*" minlevel="Trace" maxlevel="Info" writeTo="log_target_info" />
    </rules>
  </nlog>


In an ASP.NET environment, doesn't NLog "terminate" and close the file at some point before the page is rendered and the response is sent back to the browser?  I don't have any other web apps running.

Any idea what's going on here?

Thanks.

Jaroslaw Kowalski

Re: Archiving problem: cannot access the file because it is being used by another process.

Reply Threaded More More options
Print post
Permalink
How often does this happen? I suspect some antivirus may be messing up with the file. Can you try disabling AV scanning of log files?
 
Jarek

On Fri, Sep 11, 2009 at 12:14 PM, leahcimp (via Nabble) <[hidden email]> wrote:
I am trying to enable archiving, but I'm getting an internal NLog exception when NLog attempts to move the log file to my archive directory.  I am developing an ASP.NET application with VS2008.  

Here is the exception:

2009-09-11 14:58:36.2201 Error Target exception: System.IO.IOException: The process cannot access the file because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.__Error.WinIOError()
   at System.IO.File.Move(String sourceFileName, String destFileName)
   at NLog.Targets.FileTarget.SequentialArchive(String fileName, String pattern)
   at NLog.Targets.FileTarget.DoAutoArchive(String fileName, LogEventInfo ev)
   at NLog.Targets.FileTarget.Write(LogEventInfo logEvent)
   at NLog.LoggerImpl.Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)


Here is my (very basic) NLog config:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         internalLogFile="logs/log_nlogInternal.txt" >
    <targets>
        <target name="log_target_info" xsi:type="File"
                layout="${longdate} | ${callsite} | ${level} | ${message}"
                fileName="${basedir}/logs/log_info.txt"
                archiveFileName="${basedir}/logs/archive/log_info.{#####}.txt"
                archiveEvery="Minute"
                archiveNumbering="Sequence"
                concurrentWrites="false"
                keepFileOpen="false"
                />
    </targets>

    <rules>
      <logger name="*" minlevel="Trace" maxlevel="Info" writeTo="log_target_info" />
    </rules>
  </nlog>


In an ASP.NET environment, doesn't NLog "terminate" and close the file at some point before the page is rendered and the response is sent back to the browser?  I don't have any other web apps running.

Any idea what's going on here?

Thanks.


leahcimp

Re: Archiving problem: cannot access the file because it is being used by another process.

Reply Threaded More More options
Print post
Permalink
Good call, that was the problem!   Disabled my AV and it's archiving correctly now.

(BTW, NLog is great... keep up the good work).

Thanks for the help.

-leahcimp