Saturday 15 March 2014

c# - Initialize log4net settings from database -


Currently my application (C # console app) uses the file to start the log 4 net, there are log4net from the database Is there a way to initialize the configuration?

I can either save my current file as XML in DB (SQL), but I'm not sure how to get started log4net from within my app.

Edit:

Current implementation:

  _logger = log4net.LogManager.GetLogger (System.Reflection.MethodBase.GetCurrentMethod (.) Disclaimer type ); Var File = New FileInfo (System Configuration Configuration Manager. AppSettings ["log4net.Config"]); Log4net.config.xmlConfigurator.Configure (file);   

App settings are the location of the physical file in which the following is:

  & lt; Log4net & gt; & Lt; Appender Name = "File Affair" type = "Log4 Net .appear rolling file appleper" & gt; & Lt; File type = "log4net.Util.PatternString" value = "c: \% property {login name}" /> & Lt; AppendToFile value = "true" /> & Lt; Rolling style value = "date" /> & Lt; StaticLogFileName value = "wrong" /> & Lt; DatePattern value = "MM-dd-yyyy'.log '" /> & Lt; Layout type = "log4net.Layout.PatternLayout" & gt; & Lt; Conversion pattern value = "% date [% thread]% -5 level \"% message% newline \ /> & Lt; / Layout & gt; & Lt; / Appender & gt; & Lt; Root & gt; & Lt; Epander-Reef Ref = "filepeeder" /> & Lt; / Root & gt; & Lt; / Log4net & gt;    

There is one - so that you can read your configuration from the database, change it Stream, and pass that method:

  string config = GetConfigFromDb (); {Log4net.Config.XmlConfigurator.Configure (ms);}     (using the worm memorystream MS = new memorystream (encoding. ASCIINetabets (config))

No comments:

Post a Comment