Is there a way to configure ILogger to use single line unless message itself is multiline?

67 views Asked by At

When my configuring ILogger looks like this:

            services.AddLogging(options =>
            {
                options.AddSimpleConsole(c =>
                {
                    c.SingleLine = false;
                });
            });

I will get multiline output even for simpliest messages:

[08T15:30:49] dbug: Lala.WebUI.Shared.DataManagerHub[0]
      SaveLanguages in 0s.

The first line is ILogger stuff, the second line is mine. OK, so I switch option to true and it works fine until my message is multiline -- in such cases ILogger default implementation squeezes everything into single line.

So my question is there an option to make the "header/prefix" and the message first line as single line. So it could look like this:

Single line message:

[08T15:30:49] dbug: Lala.WebUI.Shared.DataManagerHub[0] SaveLanguages in 0s.

Multiline message:

[08T15:30:49] dbug: Microsoft.Extensions.Hosting.Internal.Host[4] Hosting stopped
Unhandled exception. Xunit.Sdk.FailException: Assert.Fail(): An error occurred while saving the entity changes. SQLite Error 19: 'FOREIGN KEY constraint failed'. from MeasureAsync in /home/mist/Projekty/lala/app/Lala.WebUI.Shared/CommonPostDataWorkerBase.cs at line 45
0

There are 0 answers