-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Not showing Exception stack trace in "Exception" field of the log #388
Comments
Exception.StackTrace is logged in Serilog and is not owned by our project. There are other Serilog packages that can allow you to omit it. If you'd like Serilog.Exceptions to do the same, we'd take a PR. |
Can you please let me know which package would allow me to omit it? |
I believe it was called Serilog Expressions. The creator of Serilog blogged about it. |
@jaslam94 https://github.com/destructurama and ByIgnoring project I guess would be a start point. You could also write one yourself, it seems it would not be much more than:
@RehanSaeed do you think we should include this function in the package. I could provide PR, which seems straighforward. |
@krajek Adding another boolean option to remove it from ``Exception.StackTrace` seems sensible. |
Correct me if I am wrong, but this would be used to remove a field from the Properties section of the log, not the Exception field which is a separate field. I have already tried it before opening the issue. In the above example, there is one field called Exception and the other is called ExceptionDetails. ExceptionDetails is a child of Properties. By default, ExceptionDetails does not contain stack trace. I have added it myself to it by using The issue, however, is that the stack trace gets stringified in the value of the Exception field. Hence the only solution I could think of is to prevent the Exception field from being written to the log altogether or not include stack trace to Exception field of the log. |
@jaslam94 I haven't tried it, but wouldn't that be enough to remove the
|
Nope. It won't work. That would remove any given field under Properties section of the log. While I want to remove the Exception field that is not a part of Properties. Check the following JSON:
See Properties field and then Exception field above it. I want to remove the Exception field or stack trace from the stringified value of the Exception field. |
By default, the ExceptionDetails field comes under Properties. The I have also asked a question on SO, kindly check it as well: https://stackoverflow.com/questions/69028506/log-without-exception-stack-trace-in-serilog |
@jaslam94 you are right, thanks for the explanation. Ok, that said, can you explain why would you want something else than default behavior. At the point when we decided on that set up, it seemed reasonable, because no information is lost and no memory/bandwith/storage is wasted. Could you elaborate a little bit on your scenario? |
StackTrace is a property of Exception object in C#. The field StackTrace in ExceptionDetails is logged as property and that's how an exception object should be logged. The structure of the exception object should be preserved. Your package does it just right. I think rather than removing StackTrace from ExceptionDetails based on the reason that it is already logged in by the default Serilog implementation, overlooks the fact that the default exception logging by Serilog is simply unstructured and looks ugly. Here is how it looks:
The above "default behaviour" contains the exception name, message and stack trace all joined and written together. It is unstructured. Don't get me wrong but what's the point in using a separate package which logs the exception object in its structure but also having to keep the unstructured implementation in the log as well? As a user, I would want to see one structured section in the log that shows me everything related to the exception object. i.e. ExceptionDetails. BTW, your package also allows renaming ExceptionDetails section. I can rename it to Exception only. Second, if both the default |
Would this solve this issue? |
Describe the feature
Here is an exception logged using
Seriolog.Exceptions
in a json file:A part of my logger configuration with ExceptionDetails and RollingFile configuration is:
.Enrich.WithExceptionDetails( new DestructuringOptionsBuilder() .WithDefaultDestructurers()) .WriteTo.RollingFile(new JsonFormatter(","), HttpContext.Current.Server.MapPath($"~/logs/log-.json"));
With the above configuration, the stack trace displays inside the "ExceptionDetails" section which is just right.
I understand that I am using the new JsonFormatter() in the RollingFile sink, hence the Exception field inside the LogEvent object gets logged as Exception.ToString() and the stack trace becomes a part of the value of the "Exception" field in the log. But there is no need to display stack trace there when it can be shown as a separate field inside the "ExceptionDetails".
There should be an option in Exception Destructuring to show stack trace as a part of the value of the "Exception" or remove the "Exception" field altogether when the "ExceptionDetails" section is being written to the log.
The text was updated successfully, but these errors were encountered: