Jihad Haddad
Jihad Haddad

Reputation: 640

log4net for crucial logging

Our customer has a web service which we must call, and they require us to log all traffic to the web service. That is we have to log input and output of the calls to the service and it is very crucial that all log entries be available. Is log4net suitable for such crucial logging? We have for example experienced a feature with log4net, that if we are logging to a database, and the connection is lost, it will not be reestablished by default. Moreover, log4net is asynchronous by default as far as I know, meaning that there is a risk of losing some log items or a risk of informing the user that the call went well, even though the log operation failed. Does anyone have any comment on the above?

Upvotes: 0

Views: 60

Answers (1)

stuartd
stuartd

Reputation: 73253

As the log4net FAQ states:

Is log4net a reliable logging system?

No. log4net is not reliable. It is a best-effort and fail-stop logging system.

What this means is that log4net will try its hardest to complete the logging operation, but if it should fail for any reason, log4net will not disrupt the hosting application:

log4net will not revert to System.Console.Out or System.Console.Error when its designated output stream is not opened, is not writable or becomes full. … However, log4net will output a single message to System.Console.Error and System.Diagnostics.Trace indicating that logging can not be performed

Depending on what tech the web service client is built in, it may include message tracing capability (like WCF tracing which can be enabled in the client) or you may have to build something into the client yourself to do this.

But, if it is crucial that the message is logged, don't rely on log4net.

Upvotes: 2

Related Questions