/// <summary> /// constructor that initialize logger name, file name and log level /// </summary> public CLogger(string sLoggerName, string sFilename, int iLogLevel) { ILog oLogger = LogManager.GetLogger(sLoggerName); string sLogFileName = string.Empty; sLogFileName = GetLogFileName(sFilename); m_oFPLogger = (log4net.Repository.Hierarchy.Logger)oLogger.Logger; log4net.Appender.RollingFileAppender oFPAppender = new RollingFileAppender(); oFPAppender.File = sLogFileName; oFPAppender.MaxSizeRollBackups = 100; oFPAppender.MaximumFileSize = "1MB"; oFPAppender.RollingStyle = RollingFileAppender.RollingMode.Size; oFPAppender.StaticLogFileName = true; oFPAppender.AppendToFile = true; log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout(); layout.ConversionPattern = "%d %-5p - %m%n%exception"; layout.ActivateOptions(); oFPAppender.Layout = layout; oFPAppender.ActivateOptions(); /** Programmatically configuration will not work it it is not set true**/ m_oFPLogger.Hierarchy.Configured = true; try { m_oFPLogger.AddAppender(oFPAppender); } catch (Exception ex) { throw new Exception("Failed to Add Appender", ex); } m_oFPLogger.Hierarchy.Root.Level = m_oFPLogger.Hierarchy.LevelMap[GetLogLevel(iLogLevel)]; oLogger = null; }
static HospitalLogger() { Log = LogManager.GetLogger(typeof(HospitalLogger)); Logger = (log4net.Repository.Hierarchy.Logger)Log.Logger; _loggerLevel = LoggerState.All; AppendersTypes = new List <Type>(); }
private static void SetUpFileLogger() { string filePattern = "%date %-15.15thread %-5level: %message%newline"; log4net.Layout.ILayout layout; log4net.Layout.PatternLayout normalTextLayout = new log4net.Layout.PatternLayout(filePattern); normalTextLayout.ActivateOptions(); layout = normalTextLayout; log4net.Appender.FileAppender fileAppender = new log4net.Appender.FileAppender(); fileAppender.AppendToFile = false; fileAppender.Encoding = Encoding.UTF8; fileAppender.File = Paths.LogPath; fileAppender.ImmediateFlush = true; fileAppender.Layout = layout; fileAppender.LockingModel = new log4net.Appender.FileAppender.ExclusiveLock(); fileAppender.Name = "File appender"; fileAppender.Threshold = log4net.Core.Level.Debug; fileAppender.ActivateOptions(); // A slight bit of hackery in order to programatically set more than one appender (which isn't supported by BasicConfigurator) log4net.Repository.Hierarchy.Logger root = ((log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository()).Root; root.AddAppender(fileAppender); root.Repository.Configured = true; }
/// <summary> /// 动态改变日志文件的纪录路径 /// </summary> public static void ChangeRollingFilePath(string logPath) { if (IsLoaded) { return; } try { if (!string.IsNullOrEmpty(logPath)) { logPath = Path.Combine(logPath, "ErrorLog"); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } log4net.Repository.Hierarchy.Logger root = ((log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository()).Root; root.Level = log4net.Core.Level.Debug; log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender(); string strFilePath = Path.Combine(logPath, "log_system.log"); appender.File = strFilePath; appender.AppendToFile = true; appender.MaxSizeRollBackups = 5; appender.MaximumFileSize = "1MB"; appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Size; appender.StaticLogFileName = false; appender.Encoding = Encoding.UTF8; appender.LockingModel = new log4net.Appender.FileAppender.MinimalLock(); appender.DatePattern = "yyyy-MM-dd"; appender.Layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level - %message%newline"); appender.ActivateOptions(); log4net.Config.BasicConfigurator.Configure(appender); IsLoaded = true; } } catch (Exception ex) { string TempPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (System.IO.Directory.Exists(TempPath)) { TempPath = Path.Combine(TempPath, "imobie"); TempPath = Path.Combine(TempPath, "ErrorLog"); if (!System.IO.Directory.Exists(TempPath)) { Directory.CreateDirectory(TempPath); } TempPath = Path.Combine(TempPath, "logfile.txt"); if (File.Exists(TempPath)) { File.Delete(TempPath); } FileStream fs1 = File.Create(TempPath); fs1.Close(); StreamWriter sw = new StreamWriter(TempPath, true); sw.WriteLine("Create LogFile fail!"); sw.WriteLine("Create Path:" + (logPath != "" ? logPath : "Null")); sw.WriteLine("Failed Messsage:" + ex.Message); sw.Close(); } } }
/// <summary> /// Add a desired appender to the logger /// </summary> /// <param name="loggerName">Name of the logger to which the appender is to be added</param> /// <param name="appender">Appender to add to the logger</param> private void AddAppender(log4net.Appender.IAppender appender) { log = log4net.LogManager.GetLogger(_loggerName); log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger; l.AddAppender(appender); }
public static void SetLevel(string loggerName, string levelName) { ILog log = LogManager.GetLogger(loggerName); log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger; l.Level = l.Hierarchy.LevelMap[levelName]; }
/// <summary> /// Test that the Message property is correctly remoted /// </summary> [Test] public void TestRemotedMessageNdcPushPop() { // Setup the remoting appender ConfigureRootAppender(FixFlags.Partial); RemoteLoggingSinkImpl.Instance.Reset(); log4net.Repository.Hierarchy.Logger root = null; root = ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root; string testMessage = string.Format("test message [ {0} ]", (new Random()).Next()); using (NDC.Push("value")) {} // Log a message that will be remoted root.Log(Level.Debug, testMessage, null); // Wait for the remoted object to be delivered System.Threading.Thread.Sleep(1000); LoggingEvent[] events = RemoteLoggingSinkImpl.Instance.Events; Assert.AreEqual(1, events.Length, "Expect to receive 1 remoted event"); Assert.AreEqual(testMessage, events[0].RenderedMessage, "Expect Message match after remoting event"); }
static HospitalLogger() { Log = LogManager.GetLogger(typeof (HospitalLogger)); Logger = (log4net.Repository.Hierarchy.Logger) Log.Logger; _loggerLevel = LoggerState.All; AppendersTypes = new List<Type>(); }
} //eof method /// <summary> /// Activates debug level /// </summary> /// <sourceurl>http://geekswithblogs.net/rakker/archive/2007/08/22/114900.aspx</sourceurl> private void SetLogingLevel(string strLogLevel) { this.ConfigureLogging(); string strChecker = "WARN_INFO_DEBUG_ERROR_FATAL"; if (String.IsNullOrEmpty(strLogLevel) == true || strChecker.Contains(strLogLevel) == false) { throw new ArgumentOutOfRangeException(" The strLogLevel should be set to WARN , INFO , DEBUG ,"); } log4net.Repository.ILoggerRepository[] repositories = log4net.LogManager.GetAllRepositories(); //Configure all loggers to be at the debug level. foreach (log4net.Repository.ILoggerRepository repository in repositories) { repository.Threshold = repository.LevelMap[strLogLevel]; log4net.Repository.Hierarchy.Hierarchy hier = (log4net.Repository.Hierarchy.Hierarchy)repository; log4net.Core.ILogger[] loggers = hier.GetCurrentLoggers(); foreach (log4net.Core.ILogger logger in loggers) { ((log4net.Repository.Hierarchy.Logger)logger).Level = hier.LevelMap[strLogLevel]; } } //Configure the root logger. log4net.Repository.Hierarchy.Hierarchy h = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository(); log4net.Repository.Hierarchy.Logger rootLogger = h.Root; rootLogger.Level = h.LevelMap[strLogLevel]; }
/// <summary> /// Add a desired appender to the logger /// </summary> /// <param name="loggerName">Name of the logger to which the appender is to be added</param> /// <param name="appender">Appender to add to the logger</param> private static void AddAppender(string loggerName, log4net.Appender.IAppender appender) { log4net.ILog log = log4net.LogManager.GetLogger(loggerName); log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger; l.AddAppender(appender); }
private static void RemoveAllAppender(string loggerName) { log4net.ILog log = log4net.LogManager.GetLogger(loggerName); log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger; l.RemoveAllAppenders(); }
/// <summary> /// http://forums.asp.net/t/1969159.aspx?How+to+change+log+level+for+log4net+from+code+behind+during+the+application+up+and+running+ /// </summary> /// <param name="logLevel"></param> private void SetLogLevelTo(string logLevel) { try { log4net.Repository.ILoggerRepository[] repositories = log4net.LogManager.GetAllRepositories(); //Configure all loggers to be at the debug level. foreach (log4net.Repository.ILoggerRepository repository in repositories) { repository.Threshold = repository.LevelMap[logLevel]; log4net.Repository.Hierarchy.Hierarchy hier = (log4net.Repository.Hierarchy.Hierarchy)repository; log4net.Core.ILogger[] loggers = hier.GetCurrentLoggers(); foreach (log4net.Core.ILogger logger in loggers) { ((log4net.Repository.Hierarchy.Logger)logger).Level = hier.LevelMap[logLevel]; } } //Configure the root logger. log4net.Repository.Hierarchy.Hierarchy h = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository(); log4net.Repository.Hierarchy.Logger rootLogger = h.Root; rootLogger.Level = h.LevelMap[logLevel]; } catch (Exception ex) { Console.Error.WriteLine("ERROR CHANGING LOG LEVEL {0}", ex.Message); } }
static log4net.ILog GetLogImpl(string name) { log4net.Core.LogImpl _log = log4net.LogManager.GetLogger(name) as log4net.Core.LogImpl; if (_log != null) { log4net.Repository.Hierarchy.Logger _logimpl = _log.Logger as log4net.Repository.Hierarchy.Logger; if (_logimpl != null) { log4net.Repository.Hierarchy.Logger _logger = (log4net.Repository.Hierarchy.Logger)_logimpl; if (_logger.Appenders.Count == 0) { lock (m_lockObj) { if (_logger.Appenders.Count == 0) { _logger.AddAppender(GetFileAppender(name, log4net.Core.Level.Off, log4net.Core.Level.All)); _logger.AddAppender(m_allAppender); _logger.AddAppender(m_errorAppender); _logger.AddAppender(m_infoAppender); _logger.AddAppender(m_debugAppender); _logger.AddAppender(m_warnAppender); _logger.AddAppender(m_fatalAppender); //log4net.Repository.Hierarchy.Hierarchy hier = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetAllRepositories()[0]; //hier.GetAppen //log4net.Config.XmlConfigurator.Configure(//.BasicConfigurator.Configure(_appender); } } } } } //缓存 //m_logger.Set(name, _log, m_cachePolicy); return(_log); }
public static void ConfigureLog4Net(string filelogPath, LogLevel displayLogLevel, LogLevel saveLogLevel) { log4net.Repository.Hierarchy.Logger root = ((log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository()).Root; root.AddAppender(GetConsoleAppender(GetLog4NetLevel(displayLogLevel))); root.AddAppender(GetTraceAppender(GetLog4NetLevel(displayLogLevel))); root.AddAppender(GetSiteFileAppender(filelogPath, GetLog4NetLevel(saveLogLevel))); root.Repository.Configured = true; log4net.Repository.Hierarchy.Logger nhibernate = (log4net.Repository.Hierarchy.Logger)log4net.LogManager.GetLogger("NHibernate").Logger; nhibernate.AddAppender(GetNHibernateFileAppender(filelogPath, GetLog4NetLevel(saveLogLevel))); nhibernate.Additivity = false; nhibernate.Repository.Configured = true; log4net.Repository.Hierarchy.Logger autofac = (log4net.Repository.Hierarchy.Logger)log4net.LogManager.GetLogger("Autofac").Logger; autofac.AddAppender(GetSpringFileAppender(filelogPath, GetLog4NetLevel(saveLogLevel))); autofac.Additivity = false; autofac.Repository.Configured = true; Common.Logging.LogManager.Adapter = new Log4NetLoggerFactoryAdapter(); }
public void AddAppender(string appenderName, ILogger wLogger) { if (!ConfigurationManager.AppSettings.AllKeys.Contains("BackupPath")) { throw new Exception("Parameter 'BackupPath' is mandatory"); } string filename = ConfigurationManager.AppSettings["BackupPath"].ToString() + "\\" + appenderName + ".sql"; log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)wLogger; log4net.Appender.IAppender hasAppender = l.GetAppender(appenderName); if (hasAppender == null) { log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender(); appender.DatePattern = "yyyyMMdd"; appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date; appender.AppendToFile = true; appender.File = filename; appender.StaticLogFileName = true; appender.Name = appenderName; log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout(); layout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; layout.ActivateOptions(); appender.Layout = layout; appender.ActivateOptions(); l.AddAppender(appender); } }
protected Logger(log4net.Appender.IAppender appender, string logLevel) { log = log4net.LogManager.GetLogger(typeof(T)); log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger; l.Level = l.Hierarchy.LevelMap[logLevel]; l.Additivity = true; l.AddAppender(appender); }
/// <summary> /// Configures the root appender for counting and rolling /// </summary> private void ConfigureRootAppender(FixFlags fixFlags) { log4net.Repository.Hierarchy.Logger root = null; root = ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root; root.Level = Level.Debug; root.AddAppender(CreateAppender(fixFlags)); root.Repository.Configured = true; }
public void SetLevel(string levelName) { //adds the logger as a seperate hierchy, not dependant on any other logger log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger; //Applies the logger threshold level l.Level = l.Hierarchy.LevelMap[levelName.ToLower()]; }
/// <summary> /// Setup the debug log appender and attach it to a logger. /// </summary> /// <param name="logger">The logger you want to attach the event log appender to.</param> private static void SetupDebugLogAppender(log4netLogger logger) { #if DEBUG // Create the debug appender and connect it to our logger. var debugAppender = new DebugAppender(); debugAppender.Layout = FileLogLayout; debugAppender.AddFilter(GetNoAuditFilter()); logger.AddAppender(debugAppender); #endif }
/// <summary> /// 获取日志设置 /// </summary> public static ILog GetCustomLogger(string loggerName, string loggerSource, string category, bool additivity = false) { return(loggerContainer.GetOrAdd(loggerName + (category ?? "") + loggerSource, delegate(string name) { RollingFileAppender newAppender = null; TWReadParameterAppender appender = null; if (appenderContainer.ContainsKey(loggerName)) { appender = appenderContainer[loggerName]; // 判断日志路径 string filePath = appender.File; if (filePath != null && filePath.EndsWith("\\")) { if (string.IsNullOrEmpty(category)) { filePath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}.txt", filePath, loggerName, loggerSource, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day.ToString().PadLeft(2, '0')); } else { filePath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}\{6}.txt", filePath, loggerName, category, loggerSource, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day.ToString().PadLeft(2, '0')); } } newAppender = GetNewFileApender(loggerName, filePath, appender.MaxSizeRollBackups, appender.AppendToFile, true, appender.MaximumFileSize, RollingFileAppender.RollingMode.Composite, appender.DatePattern, appender.LayoutPattern); } else { newAppender = GetNewFileApender(loggerName, GetFile(category, loggerName), MAX_SIZE_ROLL_BACKUPS, true, true, MAXIMUM_FILE_SIZE, RollingFileAppender.RollingMode.Composite, DATE_PATTERN, LAYOUT_PATTERN); } log4net.Repository.Hierarchy.Hierarchy repository = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository(); log4net.Repository.Hierarchy.Logger logger = repository.LoggerFactory.CreateLogger(repository, loggerName); logger.Hierarchy = repository; logger.Parent = repository.Root; logger.Level = GetLoggerLevel(appender == null ? LEVEL : appender.Level); logger.Additivity = additivity; logger.AddAppender(newAppender); logger.Repository.Configured = true; return new LogImpl(logger); })); }
/// <summary> /// A memory appender for logging to memory during startup. Log messages will be re-logged after configuration is loaded. /// </summary> /// <param name="logger"></param> private static void SetupStartupLogAppender(log4netLogger logger) { var startupAppender = new MemoryAppender(); startupAppender.Name = STARTUP_APPENDER_NAME; startupAppender.Layout = LoggerBootstrapper.FileLogLayout; startupAppender.ActivateOptions(); logger.AddAppender(startupAppender); logger.Repository.Configured = true; }
/// <summary> /// Setup the console log appender and attach it to a logger. /// </summary> /// <param name="logger">The logger you want to attach the console log appender to.</param> /// <param name="config">The configuration for the appender.</param> private static void SetupConsoleLogAppender(log4netLogger logger) { var appender = new ConsoleAppender(); appender.Name = ConsoleLogAppenderName; appender.Layout = FileLogLayout; appender.Threshold = Level.Warn; appender.AddFilter(GetNoAuditFilter()); appender.ActivateOptions(); logger.AddAppender(appender); }
/// <summary> /// This method creates the loggers /// </summary> /// <param name="fileAppender"></param> /// <param name="loggerName"></param> private void CreateLogger(log4net.Appender.FileAppender fileAppender, string loggerName) { log4net.Repository.Hierarchy.Hierarchy hierarchy = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository(); log4net.Repository.Hierarchy.Logger logger = (log4net.Repository.Hierarchy.Logger)hierarchy.GetLogger(loggerName); if (logger.GetAppender(fileAppender.Name) == null) { logger.AddAppender(fileAppender); } hierarchy.Configured = true; }
/// <summary> /// Turns on all logging for the system. /// </summary> private void TurnOnLogging() { log4net.Repository.ILoggerRepository[] repositories = log4net.LogManager.GetAllRepositories(); IList <IAppender> toRemove; // Configure all loggers to be at the debug level. foreach (log4net.Repository.ILoggerRepository repository in repositories) { repository.Threshold = repository.LevelMap["DEBUG"]; log4net.Repository.Hierarchy.Hierarchy hier = (log4net.Repository.Hierarchy.Hierarchy)repository; log4net.Core.ILogger[] loggers = hier.GetCurrentLoggers(); foreach (log4net.Core.ILogger logger in loggers) { log4net.Repository.Hierarchy.Logger log = (log4net.Repository.Hierarchy.Logger)logger; log.Level = hier.LevelMap["DEBUG"]; log.AddAppender(new NullAppender()); toRemove = new List <IAppender>(); foreach (var appender in log.Appenders) { if (appender.GetType() != typeof(NullAppender)) { toRemove.Add(appender); } } foreach (IAppender appender in toRemove) { log.RemoveAppender(appender); } } } // Configure the root logger. log4net.Repository.Hierarchy.Hierarchy h = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository(); log4net.Repository.Hierarchy.Logger rootLogger = h.Root; rootLogger.Level = h.LevelMap["DEBUG"]; rootLogger.AddAppender(new NullAppender()); toRemove = new List <IAppender>(); foreach (var appender in rootLogger.Appenders) { if (appender.GetType() != typeof(NullAppender)) { toRemove.Add(appender); } } foreach (IAppender appender in toRemove) { rootLogger.RemoveAppender(appender); } }
public static void AddAppender2(ILog log, IAppender appender) { log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger; if (l.GetAppender(appender.Name) != null) { return; } l.Additivity = false; l.AddAppender(appender); }
private void RemoveAllAppender() { try { log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)_log.Logger; l.RemoveAllAppenders(); } catch (Exception ex) { AppUtil.LogEvent(ex.ToString(), System.Diagnostics.EventLogEntryType.Error); } }
public void SubmitOK() { //For root log4net.Repository.Hierarchy.Hierarchy h = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository(); log4net.Repository.Hierarchy.Logger rootLogger = h.Root; rootLogger.Level = h.LevelMap[SelectedRootLogLevel.Level.ToString()]; //For custom logger log4net.Repository.ILoggerRepository log4repo = log4net.LogManager.GetRepository(); log4net.Repository.Hierarchy.Hierarchy log4hier = (log4net.Repository.Hierarchy.Hierarchy)log4repo; log4net.Core.ILogger logger4 = log4hier.GetCurrentLoggers().First(x => x.Name == "Logger4"); ((log4net.Repository.Hierarchy.Logger)logger4).Level = log4hier.LevelMap[SelectedLog4LogLevel.Level.ToString()]; }
/// <summary> /// Setup the event log appender and attach it to a logger. /// </summary> /// <param name="logger">The logger you want to attach the event log appender to.</param> /// <param name="config">The configuration for the appender.</param> private static void SetupEventLogAppender(log4netLogger logger, ILogConfig config) { #if NET45 var appender = new EventLogAppender(); appender.Layout = eventLoggerLayout; appender.Name = EventLogAppenderName; appender.LogName = EventLogName; appender.ApplicationName = EventLogSourceName; appender.AddFilter(GetNoAuditFilter()); appender.ActivateOptions(); logger.AddAppender(appender); #endif }
/// <summary> /// A temporary event log appender for logging during startup (before config is loaded) /// </summary> /// <param name="logger"></param> private static void SetupTemporaryEventLogAppender(log4netLogger logger) { #if NET45 var appender = new EventLogAppender(); appender.Layout = eventLoggerLayout; appender.Name = TemporaryEventLogAppenderName; appender.LogName = EventLogName; appender.ApplicationName = EventLogSourceName; appender.Threshold = Level.Warn; appender.AddFilter(GetNoAuditFilter()); appender.ActivateOptions(); logger.AddAppender(appender); #endif }
public static void OnChange() { bool[] logLevel = new bool[2]; int bufferSize = bufferDefaultSize; lock (syncLock) { if (_timeFired != null) { if (DateTime.Now.Subtract(_timeFired).TotalMilliseconds < 50) { return; } } _timeFired = DateTime.Now; System.Configuration.ConfigurationManager.RefreshSection("appSettings"); logLevel = ReadConfig(out bufferSize); } string loggerName = LoggingInformation.GetStaticLoggerName(LoggerNames.SocketServerLogs.ToString()); if (loggerName != null) { log4net.ILog log = log4net.LogManager.GetLogger(loggerName); log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger; BufferingAppenderSkeleton buffered = (BufferingAppenderSkeleton)l.GetAppender("BufferingForwardingAppender" + loggerName); if (buffered is BufferingForwardingAppender) { ((BufferingForwardingAppender)buffered).Flush(); } } //if not already initialized Log4net.Initialize(LoggerNames.SocketServerLogs); NCacheLog.SetLevel(LoggerNames.SocketServerLogs.ToString(), logLevel[1] == true ? NCacheLog.Level.ALL : logLevel[0] == true ? NCacheLog.Level.INFO : NCacheLog.Level.OFF); if (bufferSize < 1) { bufferSize = bufferDefaultSize; } NCacheLog.SetBufferSize(bufferSize); }
/// <summary> /// Setup the file log appender and attach it to a logger. /// </summary> /// <param name="logger">The logger you want to attach the file appender to.</param> /// <param name="config">The configuration for the appender.</param> /// <exception cref="System.Exception">If an exception occurs, the Event Log Appender is setup /// to handle output.</exception> private static void SetupFileLogAppender(log4netLogger logger, ILogConfig config) { string logFileName = config.GetFullLogFileName(); try { var appender = SetupRollingFileAppender(config, logFileName, "FileLog", FileLogLayout); appender.AddFilter(GetNoAuditFilter()); appender.ActivateOptions(); logger.AddAppender(appender); } catch (Exception) { // Fallback to the event logger if we cannot setup a file logger. SetupEventLogAppender(logger, config); } }
private static void ShutdownStartupLogAppender(log4netLogger logger) { var startupAppender = logger.GetAppender(STARTUP_APPENDER_NAME) as MemoryAppender; if (startupAppender != null) { LoggingEvent[] events = startupAppender.GetEvents(); logger.RemoveAppender(startupAppender); if (events != null) { foreach (LoggingEvent logEvent in events) { logger.Log(logEvent.Level, logEvent.MessageObject, null); } } } }