-
Notifications
You must be signed in to change notification settings - Fork 5k
LoggerExtensions.MessageFormatter takes an exception as argument but ignores it. - TraceSourceProvider should take exception into account, even if the formatter is not null. #42341
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
Comments
This was intentional because most loggers want to do special formatting for the exception (that's why it's passed into the log call itself). To avoid the breaking change of removing the formatting of the exception was the only reasonable choice.
We should fix the TraceSourceLogger to write the exception. |
Thx for the clarification, do I need to create another issue for the TraceSourceLogger, or do you take care of it? |
You can re-title this issue and send a PR 😁. |
Ok, I will do that after my holidays (in about 3 weeks).
Br
David Fowler <[email protected]> schrieb am Sa., 25. Juli 2020,
17:45:
… You can re-title this issue and send a PR 😁.
cc @maryamariyan <https://github.com/maryamariyan>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://github.com/dotnet/extensions/issues/3359#issuecomment-663869589>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGCMYRQQ33U32KTFNHTSR3R5L4XXANCNFSM4O2F2LHA>
.
|
Should The |
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @maryamariyan |
Just to restate what's going on here with some code. TraceSourceLogger only includes the exception when a formatter is not present: runtime/src/libraries/Microsoft.Extensions.Logging.TraceSource/src/TraceSourceLogger.cs Lines 26 to 40 in 8933510
The default formatter used doesn't include exception: runtime/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerExtensions.cs Lines 425 to 428 in 92b125f
As @KalleOlaviNiemitalo mentions above, @BrennanConroy stated this was by-design in aspnet/Announcements#148 We can look at other ILogger implementations and they all include the exception, even when formatter is not null. runtime/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogLogger.cs Lines 115 to 118 in 92b125f
runtime/src/libraries/Microsoft.Extensions.Logging.Console/src/JsonConsoleFormatter.cs Lines 59 to 67 in 92b125f
runtime/src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs Lines 94 to 98 in 92b125f
etc...
I don't think so. That's a public API that already defines behavior for We just need to be sure to add the exception to the message even in the case formatter is non-null, just like the other ILogger implementations. |
@rizi I marked it as up for grabs if you wanted to submit a PR. Thanks for the report! |
@ericstj I will definitely send a pull request as soon as possible. |
@ericstj so method " MessageFormatter " "private static string MessageFormatter(FormattedLogValues state, Exception error)" should include the exception details as well correct , if it is my correct understanding about the issue ? since i would like to do pr . |
I don't think so. If it did that would cause duplicate exception logging. My understanding is that the default formatter delegate |
@ericstj Are the tests in a different solution or are there no tests atm? br |
Can someone please help me to compile the Microsoft.Extensions.Logging.sln Here is what I did so far: build.cmd clr+libs -rc Release (finished with 0 warnings and 0 errors) As soon as VS 2019 (16.8 preview 3) opens I can't compile the solution or run tests: It seems that VS(nuget restore) are confused with Is there no way make Visual Studio work? Compiling the solution via command like works fine (0 errors, 0 warnings). Br |
The restore error is caused by #32205. You should be able to workaround it by restoring from the commandline and disabling restore in VS. This seems to be a worse state than it should be and I've asked some folks to follow up. |
Thx for your patience and support, I will try it tomorrow. Br |
@ericstj your solution was working fine, thx. |
Describe the bug
We are using Asp.net Core (3.1) and the "TraceSourceProvider" (
logging.AddTraceSource(sourceSwitchName)
, which in turn uses theMicrosoft.Extensions.Logging.TraceSource.TraceSourceLogger
--> the TraceSourceLogger relies on the given MessageFormatter and does nothing withe the given exception.Because
Func<TState, Exception, string> formatter
of theILogger
interface is not null theTraceSourceLogger
"thinks" the exception has already been taken into account by the formatter and does not add the exception (message/stacktrace,...) to the message that will be finally logged.We are using Microsoft.Extensions.Logging 3.1.3, should this be fixed in the MessageFormatter method or should the TraceSourceLogger take care to add exception details?
To Reproduce
Steps to reproduce the behavior:
logging.AddTraceSource(sourceSwitchName)
)ILogger<SomeClass>
and log an exception, e.qlogger.LogError("some message", someException);
Expected behavior
If an exception is available it should be taken care of in the
MessageFormatter
and therfore the exception should be visible in the log file.The text was updated successfully, but these errors were encountered: