-
Notifications
You must be signed in to change notification settings - Fork 128
Description
Description
After losing access to a logging directory and regaining access, sink does not resume writing to log file. Internal error is consistently thrown.
Reproduction
- Create an empty .NET Windows Service
- Clear logging providers to de-clunk console logging.
- Implement serilog and rolling file sink (see bottom for config used)
- Map folder on local machine to L: (example C:\logs)
- Configure sink to write to L:\logs.txt
- Start App
- Disconnect L: mapping after logging started and confirmed in log file
- Confirm error message logged to console (INF level)
- Re-map L:
- Check log file - writing has no resumed
- Check console window - error still being logged
Expected behavior
Upon reconnection of directory, serilog to reconnect and continue writing. Do not expect buffering of messages during disconnect (perhaps a new buffered file sink could be looked at for this with a FIFO queue internally).
Relevant package, tooling and runtime versions
.NET8 Windows Service project
Serilog.Sinks.File 7.0
Serilog 4.3.0
Note: Issue first encountered on Serilog.Sinks.File version 6.0 and Serilog version 4.0.2. Upgraded to ensure still occurring.
Additional context
Error thrown to console on local machine:
[16:10:12 INF] [30] Worker running at: 08/28/2025 16:10:12 +01:00
2025-08-28T15:10:13.1284647Z Caught exception while emitting to sink Serilog.Sinks.File.RollingFileSink: System.IO.IOException: An unexpected network error occurred. : 'L:\logs20250828.txt'
at Microsoft.Win32.SafeHandles.SafeFileHandle.g__GetFileLengthCore|28_0()
at System.IO.Strategies.OSFileStreamStrategy.Seek(Int64 offset, SeekOrigin origin)
at System.IO.Strategies.BufferedFileStreamStrategy.Seek(Int64 offset, SeekOrigin origin)
at Serilog.Sinks.File.SharedFileSink.Serilog.Sinks.File.IFileSink.EmitOrOverflow(LogEvent logEvent)
at Serilog.Sinks.File.RollingFileSink.Emit(LogEvent logEvent)
at Serilog.Core.Sinks.SafeAggregateSink.Emit(LogEvent logEvent)
Appsettings Config:
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Debug"
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "L:\logs.txt",
"rollingInterval": "Day",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3} {SourceContext} {Message:lj}{Exception}{NewLine}",
"retainedFileCountLimit": 14,
"shared": "true"
}
}
]
}