views:

39

answers:

1

This is my situation. I have successfully implemented logging to remote syslog using log4net. However, as far as I could test, if syslog IP is not valid, all messages will not log anywhere and no exception is raised. It just does nothing.

Hence, it would be nice to have some sort of fallback. Let's say if writing to syslog fails, write to file or to database.

Is that even possible with log4net? Or would I have to configure it to log to two locations at the same time?

+2  A: 

I don't think you can do this by configuration. This issue is open in the log4net feature backlog.

If your application can eat the logging overhead, the easiest solution would be to log to an alternative appender by default.

Alternatively you could try to wrap the appender you're using in a custom appender, and implement the fallback scenario if the syslog appender throws an exception. If it doesn't swallow them silently.

From log4net FAQ:

You can implement the log4net.Appender.IAppender interface to create you own customized appender. We recommend that you extend the log4net.Appender.AppenderSkeleton class rather than starting from scratch. You should implement your custom code in a assembly separate from the log4net assembly.

To get started it is worth looking at the source of the log4net.Appender.TraceAppender as an example of the minimum amount of code required to get an appender working.

Third option would be to look into the source code of your appender and see if you can fork it and do the necessary customizations there.

fencliff
I was hoping it can be done. I am using quick and dirty solution. Double logging. Will user RollingFileAppender though.
Vladimir Kocjancic