public void TestFirstLog4Net() { log4net.ILog log = log4net.LogManager.GetLogger(this.GetType()); log4net.Config.XmlConfigurator.Configure(); log4net.Repository.Hierarchy.Hierarchy h = (Hierarchy)log4net.LogManager.GetRepository(); var adoAppenders = h.GetAppenders().OfType <AdoNetAppender>(); //adoAppender.ConnectionString = "Data Source=XE;User ID=APPLICATIONDB;Password=password"; //adoAppender.CommandText = "INSERT INTO LOG4NET (LOG_ID, LOG_DATE, LOG_LEVEL, LOG_IDENTITY, LOG_MESSAGE, LOG_EXCEPTION) VALUES (LOG4NET_SEQ.nextval, :log_date, :log_level, :log_identity, :log_message, :log_exception)"; foreach (var appender in adoAppenders) { appender.ConnectionString = ConfigurationManager.ConnectionStrings["OraDB_Log"].ConnectionString; appender.ActivateOptions(); } log.Info("hello world!"); }
public SyncServiceLogAppender(string fileLocation, long storeLocationID) { log4net.Repository.Hierarchy.Hierarchy repository = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository(); if (fileLocation != "") { LoggerSimple.WriteMessage("Creating logger...." + fileLocation); var appenders = repository.GetAppenders(); if (appenders.FirstOrDefault(i => i.Name == "ASyncServiceLogAppender-" + storeLocationID) != null) { return; } SyncServiceFileAppender originalAppender = appenders.FirstOrDefault(i => i.Name == "SyncServiceLogAppender-0") as SyncServiceFileAppender; //(appenders[0] as SyncServiceFileAppender); SyncServiceFileAppender fileAppender = new SyncServiceFileAppender(); fileAppender.Name = "ASyncServiceLogAppender-" + storeLocationID; fileAppender.File = fileLocation; fileAppender.AppendToFile = true; fileAppender.MaxSizeRollBackups = originalAppender.MaxSizeRollBackups; fileAppender.MaximumFileSize = originalAppender.MaximumFileSize; fileAppender.RollingStyle = originalAppender.RollingStyle; fileAppender.MaximumFileSize = originalAppender.MaximumFileSize; fileAppender.CountDirection = originalAppender.CountDirection; fileAppender.DatePattern = originalAppender.DatePattern; fileAppender.ImmediateFlush = originalAppender.ImmediateFlush; fileAppender.MaxFileSize = originalAppender.MaxFileSize; fileAppender.StaticLogFileName = false; fileAppender.Threshold = log4net.Core.Level.All; fileAppender.Layout = originalAppender.Layout; fileAppender.LockingModel = new FileAppender.MinimalLock(); fileAppender.ActivateOptions(); fileAppender.FilePath = fileLocation; log4net.Repository.Hierarchy.Logger logger = (log4net.Repository.Hierarchy.Logger)repository.GetLogger("ASyncServiceLogAppender-" + storeLocationID); logger.AddAppender(fileAppender); LoggerSimple.WriteMessage("Logger Created..." + storeLocationID); Writer = LogManager.GetLogger("ASyncServiceLogAppender-" + storeLocationID); } else { Writer = LogManager.GetLogger("SyncServiceLogAppender-" + storeLocationID); } }