question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Newline character skipped when log message is 120 characters long (.Net Core)

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
olegkucommented, Apr 26, 2021
1reaction
Macaddict42commented, Aug 2, 2019

I’ll try and make a sample project to reproduce the issue in the morning.

Read more comments on GitHub >

github_iconTop Results From Across the Web

split a string on newlines in .NET
On a non-*nix system that will split on the separate characters in the Newline string, i.e. the CR and LF characters. That will...
Read more >
Environment.NewLine Property (System)
The property value of NewLine is a constant customized specifically for the current platform and implementation of the .NET Framework. For more information ......
Read more >
Are 80 Characters Per Line Still Reasonable In 2020?
The 80 character line length is optimal for English word lengths, because that gives you an optimal number of words per line to...
Read more >
Newline
A newline is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. This character...
Read more >
Why do newline characters get lost when using command ...
Newlines get swapped out at some points because they are special characters. In order to keep them, you need to make sure they're...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found