How to use multiple appender in same log4net config file? Also provide how to dynamically select appenders in C# code to write logs.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can configure multiple appenders very easily. For example like this:
The second part is harder to answer: The idea is not to select an appender and write to it. Normally you use loggers and simply write whatever you think is useful at an appropriate log level. You do not care where your log messages are written to: This is for the system administrator to decide (IMHO).
It is actually possible to use different appenders for different loggers. A system administrator might decide to log all errors in a YourApp.Security namespace to a SMTP appender while the rest simply goes to a database or a file. More information on loggers can be found in this excellent tutorial:
http://www.beefycode.com/post/Log4Net-Tutorial-pt-5-Using-Logger-Objects.aspx
It is however possible to create appenders in code (sample code can be found here) but the question is if you really want to do this. Example: If you want to send an email in certain situations then I suggest not use log4net. Instead you simply create and send the email in your own code.