Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi Friends,

I have developed the code to log the defacts in the database as well as in the file.using the log4net configuration file.

The problem i have is how to make it configurable means either on the database level or on the file level.and how to decide at a time log the defacts in the database or in file with out changing the log4net configuration

I have placed the appender
XML
<appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">

and appender referance as
XML
<pre> <appender-ref ref="AdoNetAppender_SqlServer" />


and my logger class constructor is

C#
public Logger()
       {

         FileInfo log4netConfig = new FileInfo(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

           Configure(log4netConfig.Directory + "\\log4net.config");//////line 1
           log4net.Config.XmlConfigurator.Configure();/////////////line 2
           Log = LogManager.GetLogger("root");
       }


Can we manage the database or the file setting in this constructor??

Please Help me
Thanks in advance
Posted

1 solution

You can add and remove appenders at runtime. Maybe this[^] link will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900