开发者

Need Help in Setting Appender Name through a separate configuration file like app.config or web.config

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 vi开发者_开发百科a 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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜