-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add support for the InnerException(s) logging into Microsoft.Extensions.Logging.Console json formatter. #40507
Comments
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 |
If you're changing JsonConsoleFormatter to format Exception.InnerException (recursively or as a string), then I think it should use AggregateException.InnerExceptions instead when available. |
Note: (
behavior: merge and print out distinct (innerexception+InnerExceptions) by calling .ToString() for each of them! |
@dmitriyse for this proposal it would help if you could please provide an example logging usage and expected/actual output for it. |
Seems like the best way forward for issue is if we changed the output from To rather just have
where X is the exception.ToString() content (similar to what is done in SystemdConsoleFormatter or SimpleConsoleFormatter) and when FormatterOptions.JsonWriterOptions.Indented is false for JsonConsoleFormatter to write the exception.ToString() content in single line changing new lines to a whitespace otherwise with \n. |
@maryamariyan your proposal looks nice and simple but i think the main purpose of this logger was providing output with more (predictable) structured output details specially for other engines that are interpreting logs (ApplicationInsights et.al) the more complex way (and not easy to implement) may be using the full capabilities to implement hierarchies inside Json:
using "InnerExceptions" (plural) as array allows to implement BOTH core usecases:
btw.: Exception.Data should also be added on every level of exception...(#35922 ) |
i have created a first draft that implements InnerExceptions AND Exception.Data output: The test is creating the following exception hierarchy:
and the reuslting json looks like:
if we agree to go this way, i can polish the code and prepare a PR |
@WernerMairl the proposal looks good and is an improvement to what is already there. A limitation to it though is that sometimes different exception types may embed extra content into exception.ToString that would otherwise get lost if we not use ToString instead. |
I am wondering, do we also handle the AggregateException? |
Yes, AggregateException is covered by the implementation! |
About exception.ToString() and extra content On the other side, we have a lot of problems/risks with Exception.ToString: Assuming that we cannot do significant changes on System.Exception.ToString() I'm proposing the following a) logging extension should ignore Exception.ToString() because output content and format is not predictable. For the moment the Jsonformatter is following exactly the way proposed above, and maybe we should follow the same way for the other Console Loggers.... just my 2 cent... |
Exception.InnerException and AggregateException.InnerExceptions are added to the Json output. Fix dotnet#40507
It would be as unpredictable for SystemdConsoleFormatter and SimpleConsoleFormatter, and we would still be left inconsistent if we keep using exception.ToString() for the other two formatter.
I think you're thinking in terms of using JsonConsoleFormatterOptions for further customization. If so, I believe there is no such customization yet for Exception.Data. Your PR is a definite improvement to what is already in the code base, which is not using System.Exception.ToString(). I think for us to completely move away from exception.ToString, a little bit more design discussion needs to happen, perhaps coming up with some customization as you said. My thought process is for 5.0 maybe we can switch back to using ToString instead. Perhaps we could move away from it in 6.0 timeframe when we have properly designed it and have clear ideas for the other two formatters as well. That said if others provide approvals for the PR then we could go right ahead with your approach. |
Exception.InnerException and AggregateException.InnerExceptions are added to the Json output. Fix dotnet#40507
Background and Motivation
In the .Net 5.0 JSON formatter was added to the console logger.
But it's current implementation lacks the output of the
Exception.InnerException
information which is 100% useful.See #34742
Proposed API
Add Exception.ToString() into additional JSON field (FullExceptionDetail).
Optionally this feature can be controlled by some flag in the JsonConsoleFormatterOptions
For example: IncludeFullExceptionDetail
Alternative
Add recursion into Exception.InnerException formatting.
The text was updated successfully, but these errors were encountered: