Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Each trace record includes an extra message: <program name> <trace level> # #20

Open
ATECoder opened this issue Feb 11, 2021 · 4 comments

Comments

@ATECoder
Copy link

Serilog Sinks Trace works like a charm but seems to added an extra record before each log message. Is there a way to control this behavior?

To demonstrate, I am showing below the Console log messages (each tagged with a c::) and the Trace messages (each tagged with a t::). The trace messages where stored in a queue, which is dumped for testing purposes.

Here is the Console trace messages:
`
c::20:46:08.731 -08:00, [INF], (isr.Core.Logging.Tester.Program), Starting application...

c::20:46:08.759 -08:00, [INF], (isr.Core.Logging.Tester.App), Running application.

c::20:46:08.803 -08:00, [INF], (isr.Core.Logging.Tester.App), Logging into C:\My\Libraries\VS\Core\Core5\src\Testers\Logging\bin\Debug_Logs\lime_20210210.log.

c::20:46:08.810 -08:00, [DBG], (isr.Core.Logging.Tester.TestService), Running logging service.

c::20:46:08.817 -08:00, [DBG], (isr.Core.Logging.Tester.TestService), Throwing divide by zero exception.

c::20:46:08.835 -08:00, [ERR], (isr.Core.Logging.Tester.App), reporting exception

System.InvalidOperationException: Caught in App

---> System.DivideByZeroException: Attempted to divide by zero.

at isr.Core.Logging.Tester.TestService.Run() in C:\My\Libraries\VS\Core\Core5\src\Testers\Logging\Program\Program.cs:line 309

at isr.Core.Logging.Tester.App.Run() in C:\My\Libraries\VS\Core\Core5\src\Testers\Logging\Program\Program.cs:line 249

--- End of inner exception stack trace ---
`

And here are the trace messages where each line is preceded by the name of the program (LoggingTester) , the trace level (e.g., information) and a zero.

`
--- Queue Trace Listener Records after flush:

LoggingTester Information: 0 :

t::20:40:22.955 -08:00, [INF], (isr.Core.Logging.Tester.Program), Starting application...

LoggingTester Information: 0 :

t::20:40:22.979 -08:00, [INF], (isr.Core.Logging.Tester.App), Running application.

LoggingTester Information: 0 :

t::20:40:23.024 -08:00, [INF], (isr.Core.Logging.Tester.App), Logging into C:\My\Libraries\VS\Core\Core5\src\Testers\Logging\bin\Debug_Logs\lime_20210210.log.

t::20:40:23.031 -08:00, [DBG], (isr.Core.Logging.Tester.TestService), Running logging service.

t::20:40:23.035 -08:00, [DBG], (isr.Core.Logging.Tester.TestService), Throwing divide by zero exception.

LoggingTester Error: 0 :

t::20:40:23.052 -08:00, [ERR], (isr.Core.Logging.Tester.App), reporting exception

System.InvalidOperationException: Caught in App

---> System.DivideByZeroException: Attempted to divide by zero.

at isr.Core.Logging.Tester.TestService.Run() in C:\My\Libraries\VS\Core\Core5\src\Testers\Logging\Program\Program.cs:line 309

at isr.Core.Logging.Tester.App.Run() in C:\My\Libraries\VS\Core\Core5\src\Testers\Logging\Program\Program.cs:line 249

--- End of inner exception stack trace ---

--- End of Queue Trace Listener Records
`

@ATECoder ATECoder changed the title Each trace records includes an extra message: <program name> <trace level> # Each trace record includes an extra message: <program name> <trace level> # Feb 11, 2021
@Numpsy
Copy link
Member

Numpsy commented Feb 13, 2021

Is this related to what #7 and #15 were discussing?

@ATECoder
Copy link
Author

ATECoder commented Feb 13, 2021 via email

@Numpsy
Copy link
Member

Numpsy commented Feb 13, 2021

As a side, I noticed that each Debug sink message leaks into the Trace. Is that also a Microsoft doing?

There is some overlap between the two (on .NET at least, I can't recall offhand if .NETCore is the same) - the Microsoft documentation at https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debug.listeners?view=netframework-4.8#remarks states that the Trace and Debug classes share a single listeners collection, so adding a listener to one also adds it to the other.

@ATECoder
Copy link
Author

ATECoder commented Feb 15, 2021

Per the TraceSource.TraceEvent method documentation, an override of the TraceSource.TraceEvent method could construct the message w/o the default output prefix:

"The trace content is listener specific. If the method is not overridden by the listener implementation, the default output is the name of the trace source, its numeric identity, and the event type. Additional trace content is dependent upon the listener's TraceOutputOptions property value."
https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.tracesource.traceevent?view=net-5.0

However, looking at the code of the trace listener (https://referencesource.microsoft.com/#System/compmod/system/diagnostics/TraceListener.cs,8b8ba5341c6d1740), a header is emitted by the trace listener:
`
[ComVisible(false)]
public virtual void TraceEvent(TraceEventCache eventCache, String source, TraceEventType eventType, int id, string format, params object[] args) {
if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, format, args))
return;

        WriteHeader(source, eventType, id);
        if (args != null)
            WriteLine(String.Format(CultureInfo.InvariantCulture, format, args));
        else
            WriteLine(format);

        WriteFooter(eventCache);
    }

    private void WriteHeader(String source, TraceEventType eventType, int id) {
        Write(String.Format(CultureInfo.InvariantCulture, "{0} {1}: {2} : ", source, eventType.ToString(), id.ToString(CultureInfo.InvariantCulture)));
    }

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants