views:

32

answers:

1

Hello I am Basmah, Undergraduate student. I need your help in the following scenario.

I have four appenders namely as follows

appender name= LogFileAppender // to write general logs in File

appender name=LogDatabaseAppender// to write general logs in db via Oracle StoredProc

appender name=ExceptionFileAppender // to write exception logs in File

appender name=ExceptionDatabaseAppender // to write exception logs in db via Oracle StoredProc

I want to have a appconfig file where I can set which appender to use. Moreover , I have methods as follows Method_WriteLogOnly ---> which will use appender 1 or 2 Method_WriteExceptionLogs---> which will use appender 3 or 4

Problem is I dont know if I am using the same log4net.config.xml file for both the methods , then how to set the appender .

What is the best practice , either to set appender programmatically or through another configuration place like if I have an app.config or web.config file , and there I write a key value pair (some sort of code like this) for choosing the appender ? Please guide me with code guidelines. Thankyou

A: 

I think you should not decide in code what appender to use: you should decide what is logged, but the people that run your application should decide how it is logged.

While I can understand that you want a separate file for exception, I wonder a bit why you want to use two database appenders. If you need to write to different tables then you can easily do this inside your stored procedure. This has several advantages: Configuration will be easier, you will only have one database connection...

Assuming that it would be good enough for you to say that "exceptions == messages with level ERROR" then you can easily create two appenders and use filters to make sure only messages with level ERROR end up in the "exception" log file.

Stefan Egli