At runtime, there are several ILogger.Trace() being recorded in the log file correctly, and then I see this exception:
System.IO.IOException: The process cannot access the file 'C:\......\logs-6136.log' because it is being used by another process.
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at NReco.Logging.File.FileLoggerProvider.FileWriter.<OpenFile>g__createLogFileStream|7_0(<>c__DisplayClass7_0& )
at NReco.Logging.File.FileLoggerProvider.FileWriter.OpenFile(Boolean append)
at NReco.Logging.File.FileLoggerProvider.FileWriter..ctor(FileLoggerProvider fileLogPrv)
at NReco.Logging.File.FileLoggerProvider..ctor(String fileName, FileLoggerOptions options)
at Microsoft.Extensions.Logging.FileLoggerExtensions.<>c__DisplayClass1_0.<AddFile>b__0(IServiceProvider srvPrv)
the rest of stack trace is my code, all the way back to a line in the code that tries to make another call to ILogger.Trace()
The last ILogger.Trace() call I make is after shutdown my IHost.
Seems like the LoggingProvider may be keeping the file open all the time? or perhaps we have a writing concurrency issue?
Or not correctly closing the file after exiting?
I am using the Provider once in a CLI (in rolling file configuration)
I am configuring it in code, like this:
At runtime, there are several
ILogger.Trace()
being recorded in the log file correctly, and then I see this exception:The last
ILogger.Trace()
call I make is after shutdown myIHost
.Seems like the LoggingProvider may be keeping the file open all the time? or perhaps we have a writing concurrency issue? Or not correctly closing the file after exiting?
Could that be the case?