Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

ConsoleRunHost Exception Logging #464

Closed
meinsiedler opened this issue Aug 10, 2018 · 4 comments
Closed

ConsoleRunHost Exception Logging #464

meinsiedler opened this issue Aug 10, 2018 · 4 comments

Comments

@meinsiedler
Copy link

Hi!

We are using the OnException method to register a callback for handling exceptions. In that callback, we create a custom log entry like so:

service.OnException(ex =>
{
    // some more logic ...
    Log.Fatal(ex, "An unhandled exception occurred in service.") // our custom log entry (simplified)
});

When running the service as console application, unhandled exceptions are logged twice, because in the ConsoleRunHost implementation, an error is logged too:

_log.Error("An exception occurred", ex);

Any thoughts on how to suppress the hardcoded _log.Error(...) call in the ConsoleRunHost?

@maxcherednik
Copy link
Contributor

@meinsiedler usually the logging of the internals of the library should be disabled - this is usually done with the logger configuration.

@meinsiedler
Copy link
Author

@maxcherednik Thank you for your response.

I'm not quite sure how to turn off only the internal log messages of the library. Do you have an example how to achieve that? (We are using Serilog btw.)

For our setup, it would actually be OK to log internal messages - especially the Information messages when a service starts or stops are relevant. So maybe there is a way to just ignore the above stated Error message in case of an exception?

@maxcherednik
Copy link
Contributor

This is how it's done to hide asp.net core internal logging.

https://github.com/serilog/serilog-aspnetcore#instructions

@phatboyg
Copy link
Contributor

phatboyg commented Dec 6, 2020

I am closing all issues that haven't seen any activity. You're welcome to submit a PR to resolve the issue or provide more information.

@phatboyg phatboyg closed this as completed Dec 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants