public static void Setup(string path) { // "%d[%2%t] %-5p[%-10c] %m %n" var pl = new PatternLayout {ConversionPattern = "%c%m%n"}; pl.ActivateOptions(); var fileAppender = new FileAppender { AppendToFile = true, LockingModel = new FileAppender.MinimalLock(), File = path, Layout = pl }; fileAppender.ActivateOptions(); var bufferingForwardingAppender = new BufferingForwardingAppender { Lossy = false, Fix = FixFlags.None }; bufferingForwardingAppender.AddAppender(fileAppender); bufferingForwardingAppender.ActivateOptions(); var consoleAppender = new ConsoleAppender {Layout = pl}; consoleAppender.ActivateOptions(); var hierarchy = (Hierarchy) LogManager.GetRepository(); hierarchy.Root.RemoveAllAppenders(); BasicConfigurator.Configure(hierarchy, bufferingForwardingAppender, consoleAppender); }
private IAppender NewBufferingFileAppender(string outputFile, PatternLayout layout) { var buffered = new BufferingForwardingAppender { BufferSize = bufferSize, Evaluator = new LevelEvaluator(Level.Error), Lossy = true, Fix = fixFlags, ErrorHandler = new NullErrorHandler() }; buffered.AddAppender(NewRollingFileAppender(outputFile, Level.All, layout)); buffered.ActivateOptions(); return buffered; }
public void SetupRepository() { m_hierarchy = new Repository.Hierarchy.Hierarchy(); m_countingAppender = new CountingAppender(); m_countingAppender.ActivateOptions(); m_bufferingForwardingAppender = new BufferingForwardingAppender(); m_bufferingForwardingAppender.AddAppender(m_countingAppender); m_bufferingForwardingAppender.BufferSize = 5; m_bufferingForwardingAppender.ClearFilters(); m_bufferingForwardingAppender.Fix = FixFlags.Partial; m_bufferingForwardingAppender.Lossy = false; m_bufferingForwardingAppender.LossyEvaluator = null; m_bufferingForwardingAppender.Threshold = Level.All; }
private void SetupRepository() { m_hierarchy = new Repository.Hierarchy.Hierarchy(); m_countingAppender = new CountingAppender(); m_countingAppender.ActivateOptions(); m_bufferingForwardingAppender = new BufferingForwardingAppender(); m_bufferingForwardingAppender.AddAppender(m_countingAppender); m_bufferingForwardingAppender.BufferSize = 0; m_bufferingForwardingAppender.ClearFilters(); m_bufferingForwardingAppender.Evaluator = null; m_bufferingForwardingAppender.Fix = FixFlags.Partial; m_bufferingForwardingAppender.Lossy = false; m_bufferingForwardingAppender.LossyEvaluator = null; m_bufferingForwardingAppender.Threshold = Level.All; m_bufferingForwardingAppender.ActivateOptions(); log4net.Config.BasicConfigurator.Configure(m_hierarchy, m_bufferingForwardingAppender); }
static LogManager() { var layout = new SimpleLayout(); layout.ActivateOptions(); var logAppender = new EventLogAppender {Layout = layout, LogName = EventLogConstants.EVENT_LOG_NAME}; logAppender.ActivateOptions(); var lossyAppender = new BufferingForwardingAppender { Lossy = true, BufferSize = 10, Evaluator = new log4net.Core.LevelEvaluator(log4net.Core.Level.Error) }; lossyAppender.AddAppender(logAppender); lossyAppender.ActivateOptions(); var hierarchy = (Hierarchy) log4net.LogManager.GetRepository(); Logger root = hierarchy.Root; root.Level = log4net.Core.Level.All; BasicConfigurator.Configure(lossyAppender); }
/// <summary> /// Creates Buffer Appender, Responsible for storing all logging events in memory buffer /// and writing them down when by passing the logging events on to the file appender it holds /// when its buffer becomes full /// Can also be made a lossy logger which writes only writes down to a file when a specific crieteria/condition is met /// </summary> /// <param name="cacheName">CacheName used to name the Buffer Appender</param> /// <param name="fileName">File name to log into</param> /// <returns>Returns the created Appender</returns> private log4net.Appender.IAppender CreateBufferAppender(string fileName) { log4net.Appender.BufferingForwardingAppender appender = new BufferingForwardingAppender(); appender.Name = "BufferingForwardingAppender" + _loggerName; //Pick from config int bufferSize = bufferDefaultSize; ReadConfig(out bufferSize); if (bufferSize == bufferDefaultSize) ReadClientConfig(out bufferSize); if (bufferSize < 1) bufferSize = bufferDefaultSize; appender.BufferSize = bufferSize; //Threshold is maintained by the logger rather than the appenders appender.Threshold = log4net.Core.Level.All; //Adds the appender to which it will pass on all the logging levels upon filling up the buffer appender.AddAppender(CreateRollingFileAppender(fileName)); //necessary to apply the appender property changes appender.ActivateOptions(); return appender; }