I’m using Hangfire and NLog for logging.
I followed standard procedures to configure Hangfire and NLog, but I’m getting this error:
2015-03-04 12:47:30.4733|Fatal|Fatal error occurred during execution of 'Worker #5' component. It will be stopped. See the exception for details. NLog.NLogRuntimeException: Exception occurred in NLog ---> System.IO.FileLoadException: The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at NLog.Internal.FileAppenders.BaseFileAppender.WindowsCreateFile(String fileName, Boolean allowConcurrentWrite)
at NLog.Internal.FileAppenders.BaseFileAppender.TryCreateFileStream(Boolean allowConcurrentWrite)
at NLog.Internal.FileAppenders.BaseFileAppender.CreateFileStream(Boolean allowConcurrentWrite)
at NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender.Write(Byte[] bytes)
at NLog.Targets.FileTarget.WriteToFile(String fileName, Byte[] bytes, Boolean justData)
at NLog.Targets.FileTarget.Write(LogEventInfo logEvent)
at NLog.Targets.Target.Write(AsyncLogEventInfo logEvent)
--- End of inner exception stack trace ---
at NLog.LoggerImpl.<>c__DisplayClass1.<Write>b__0(Exception ex)
at NLog.Internal.SingleCallContinuation.Function(Exception exception)
at NLog.Targets.Target.Write(AsyncLogEventInfo logEvent)
at NLog.Targets.Target.WriteAsyncLogEvent(AsyncLogEventInfo logEvent)
at NLog.LoggerImpl.WriteToTargetWithFilterChain(TargetWithFilterChain targetListHead, LogEventInfo logEvent, AsyncContinuation onException)
at NLog.LoggerImpl.Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)
at NLog.Logger.WriteToTargets(LogLevel level, IFormatProvider formatProvider, String message)
at NLog.Logger.Debug(String message)
at CallSite.Target(Closure , CallSite , Object , String )
at Hangfire.Logging.LogProviders.NLogLogProvider.NLogLogger.Log(LogLevel logLevel, Func`1 messageFunc, Exception exception)
at Hangfire.Logging.LoggerExecutionWrapper.Log(LogLevel logLevel, Func`1 messageFunc, Exception exception)
at Hangfire.Logging.LogExtensions.LogFormat(ILog logger, LogLevel logLevel, String message, Object[] args)
at Hangfire.Server.ServerSupervisor.LogComponentStarted()
at Hangfire.Server.ServerSupervisor.RunComponent() | NLogLogger.LogException => UpdateDelegates.UpdateAndExecuteVoid3 => <no type>.CallSite.Target