Newline character skipped when log message is 120 characters long (.Net Core)
See original GitHub issueI’ve been looking all over for an explaination as to why I’m getting multiple log messages on the same line.
2019-07-31 14:12:00.145 [Debug] (MyExample.Common.MessageParser) Received SendFileChunkRequest - Length: 32806 2019-07-31 14:12:00.149 [Debug] (MyExample.Common.SerialPortWrapper) Sending SendFileChunkResponse - Length: 24 2019-07-31 14:12:00.154 [Debug] (MyExample.Common.MessageParser) Received SendFileChunkRequest - Length: 79332019-07-31 14:12:00.156 [Information] (MyExample.Client.Services.OutputService) DownloadFile Complete 2019-07-31 14:12:00.156 [Debug] (MyExample.Common.SerialPortWrapper) Sending SendFileChunkResponse - Length: 24 2019-07-31 14:12:00.195 [Debug] (MyExample.Common.MessageParser) Received DownloadFileResponse - Length: 49 2019-07-31 14:12:00.197 [Information] (MyExample.Client.Program) Press any key to stop the server…
I read somewhere that this won’t happen as long as you only use a single logger. I’m doing this but I’m also using logger.ForContext() which I suspect is actually creating a new logger rather than enriching the original.
Is there any way to have a logger that includes the name of my class while still being threadsafe to avoid writing multiple messages to the same line?
.Net Core 3.0 Preview 7 Serilog: 2.8.0 Serilog.Sinks.Console 3.1.1 Serilog.Sinks.RollingFile 3.3.0
Logger registration:
var logFormat = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level}] ({SourceContext}) {Message}{NewLine}{Exception}";
container.Register<ILogger>(() => new LoggerConfiguration()
#if DEBUG
.MinimumLevel.Debug()
#else
.MinimumLevel.Information()
#endif
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: logFormat)
.WriteTo.RollingFile(logName, outputTemplate: logFormat, shared: true)
.CreateLogger(), Lifestyle.Scoped);
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (6 by maintainers)
Worth to mention that this bug is reproducible when Virtual Terminal mode is enabled: https://github.com/serilog/serilog-sinks-console/blob/65e237f685e017cbdae05ee5ff8b77b3713cf81e/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs#L37
I’ll try and make a sample project to reproduce the issue in the morning.