Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging with backup appender

Is there any .NET logging framework that have ability to switch appender if something is wrong with current one. Actually what I want is following:

If I'm using database appender and when something goes wrong with database (e.g. server goes down, lose power...) I want to switch to second appender (e.g. which log into file).

Does this ability have one of following: log4net, NLog, Enterprise Library? I was looking for this but no luck.

like image 218
zvjerka24 Avatar asked Jan 13 '12 10:01

zvjerka24


People also ask

What is a logging Appender?

The appender is the part of a logging system that's responsible for sending the log messages to some destination or medium. It answers the question "where do you want to store this stuff?"

What is logger and Appender in log4j?

Log4j provides Appender objects which are primarily responsible for printing logging messages to different destinations such as console, files, NT event logs, Swing components, JMS, remote UNIX syslog daemons, sockets, etc.

What is the purpose of the Appender?

Appenders (also called Handlers in some logging frameworks) are responsible for recording log events to a destination. Appenders use Layouts to format events before sending them to an output.


2 Answers

For completeness: Enterprise Library supports a configurable Error Special Source where you can set an "appender" to log messages that have errored. Once configured this just works without any programming.

The only downside is that it will actually log the exception that occurred along with the Log Entry details in a specific format that cannot be changed so it is not flexible. This is good for troubleshooting but it might not be ideal if you want to extract errored log messages and import them into the original logging destination (although the format is known so it would be possible to parse).

like image 55
Randy supports Monica Avatar answered Sep 30 '22 13:09

Randy supports Monica


As far as I know log4net currently does not support backup appenders, there is (or was?) an open issue in the log4net feature backlog. But I think that the project called FallbackAppender does exactly what you need.

like image 43
Igor Korkhov Avatar answered Sep 30 '22 13:09

Igor Korkhov