public Log4NetLogManagerLoggingEnabledTests() { Log4NetLogManager.ProviderIsAvailabileOverride = true; memoryAppender = new MemoryAppender(); BasicConfigurator.Configure(memoryAppender); sut = new Log4NetLogManager().GetLogger("Test"); }
public Log4NetLogProviderLoggingDisabledTests() { _memoryAppender = new MemoryAppender(); _memoryAppender.AddFilter(new DenyAllFilter()); BasicConfigurator.Configure(_memoryAppender); _sut = new Log4NetLogProvider().GetLogger("Test"); }
public Logger(string fileName) { _hierarchy = (Hierarchy) LogManager.GetRepository(); var patternLayout = new PatternLayout { ConversionPattern = "%date [%thread] %-5level %logger - %message%newline" }; patternLayout.ActivateOptions(); var roller = new FileAppender { AppendToFile = true, File = fileName, Layout = patternLayout, }; roller.ActivateOptions(); _hierarchy.Root.AddAppender(roller); var memory = new MemoryAppender(); memory.ActivateOptions(); _hierarchy.Root.AddAppender(memory); _hierarchy.Root.Level = Level.Info; _hierarchy.Configured = true; }
public static void Initialize() { var hierarchy = (Hierarchy)LogManager.GetRepository(); var patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date %-5level %logger - %message%newline"; patternLayout.ActivateOptions(); var roller = new RollingFileAppender(); roller.AppendToFile = false; roller.File = @"Logs\EventLog.txt"; roller.Layout = patternLayout; roller.MaxSizeRollBackups = 5; roller.MaximumFileSize = "1GB"; roller.RollingStyle = RollingFileAppender.RollingMode.Size; roller.StaticLogFileName = true; roller.ActivateOptions(); hierarchy.Root.AddAppender(roller); MemoryAppender memory = new MemoryAppender(); memory.ActivateOptions(); hierarchy.Root.AddAppender(memory); hierarchy.Root.Level = Level.Info; hierarchy.Configured = true; }
public static void TestJsonFormatting() { var layout = new JSONFragmentPatternLayout(); layout.ActivateOptions(); var memoryAppender = new MemoryAppender { Layout = layout, }; BasicConfigurator.Configure(memoryAppender); var log = LogManager.GetLogger(typeof(LogJsonFormattingTests)); { log.Info("Test1"); var localEvents = memoryAppender.GetEvents(); Assert.AreEqual("Test1", localEvents.Last().RenderedMessage); } { log.Info(new { Test = "Test1" }); var localEvents = memoryAppender.GetEvents(); Assert.AreEqual("{ Test = Test1 }", localEvents.Last().RenderedMessage); } { log.Info(new { Test1 = "Test1", Test2 = new { Test = "Test2" } }); var localEvents = memoryAppender.GetEvents(); Assert.AreEqual("{ Test1 = Test1, Test2 = { Test = Test2 } }", localEvents.Last().RenderedMessage); } }
public static void Setup() { Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date{dd/MM/yyyy hh:mm:ss.fff tt} | %logger[%method:%line] %level - %message%newline%exception"; patternLayout.ActivateOptions(); RollingFileAppender roller = new RollingFileAppender(); roller.AppendToFile = false; roller.Encoding = Encoding.UTF8; roller.File = DataEx.log_Events; roller.Layout = patternLayout; roller.MaxSizeRollBackups = 5; roller.MaximumFileSize = "5MB"; roller.RollingStyle = RollingFileAppender.RollingMode.Size; roller.StaticLogFileName = true; roller.ActivateOptions(); hierarchy.Root.AddAppender(roller); MemoryAppender memory = new MemoryAppender(); memory.ActivateOptions(); hierarchy.Root.AddAppender(memory); hierarchy.Root.Level = (bool)App.Current.Properties["Troubleshooting"] ? Level.Debug : Level.Info; hierarchy.Configured = true; doFirstEntry(); }
/// <summary> /// Setups the logger configuration. Can be used instead of loading log4net.config file /// </summary> public static void SetupLogger() { Hierarchy hierarchy = (Hierarchy) LogManager.GetRepository(); PatternLayout patternLayout = new DynamicPatternLayout(); patternLayout.ConversionPattern = "%date{dd MMM yyyy HH:mm:ss} [%thread] %level - %message %exception %newline"; patternLayout.ActivateOptions(); RollingFileAppender roller = new RollingFileAppender { // appends the log into same file AppendToFile = true, File = @"DeployLogs\\Deploylog.log", Layout = patternLayout, MaxSizeRollBackups = 1000, RollingStyle = RollingFileAppender.RollingMode.Date, StaticLogFileName = false }; roller.ActivateOptions(); hierarchy.Root.AddAppender(roller); MemoryAppender memoryAppender = new MemoryAppender(); memoryAppender.ActivateOptions(); hierarchy.Root.AddAppender(memoryAppender); hierarchy.Root.Level = Level.All; hierarchy.Configured = true; }
/// <summary> /// Setup Log4NET logger. /// </summary> internal static void Setup() { var hierarchy = (Hierarchy) LogManager.GetRepository(); var patternLayout = new PatternLayout { ConversionPattern = "%date [%thread] %-5level %logger - %message%newline" }; patternLayout.ActivateOptions(); var roller = new FileAppender { AppendToFile = false, File = @"AllureLog.txt", Layout = patternLayout }; roller.ActivateOptions(); hierarchy.Root.AddAppender(roller); var memory = new MemoryAppender(); memory.ActivateOptions(); hierarchy.Root.AddAppender(memory); hierarchy.Root.Level = Level.Info; hierarchy.Configured = true; }
/// <summary> /// Init log4net memoryAppender /// http://dhvik.blogspot.com/2008/08/adding-appender-to-log4net-in-runtime.html /// </summary> void InitLogger() { //First create and configure the appender this.memoryAppender = new MemoryAppender(); this.memoryAppender.Name = this.GetType().Name + "MemoryAppender"; PatternLayout layout = new PatternLayout(); layout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; layout.ActivateOptions(); this.memoryAppender.Layout = layout; //Notify the appender on the configuration changes this.memoryAppender.ActivateOptions(); //Get the logger repository hierarchy. this.repository = (Hierarchy)LogManager.GetRepository(); //and add the appender to the root level //of the logging hierarchy this.repository.Root.AddAppender(memoryAppender); //configure the logging at the root. //this.repository.Root.Level = Level.Info; //mark repository as configured and notify that is has changed. this.repository.Configured = true; this.repository.RaiseConfigurationChanged(EventArgs.Empty); this.msgWriter = new StringWriter(); }
public Log4NetLogProviderLoggingTests() { _memoryAppender = new MemoryAppender(); BasicConfigurator.Configure(_memoryAppender); _logProvider = new Log4NetLogProvider(); _sut = new LoggerExecutionWrapper(new Log4NetLogProvider().GetLogger("Test")); }
public void Database() { MemoryAppender memoryAppender = new MemoryAppender(); BasicConfigurator.Configure(LogManager.GetLogger(typeof (SchemaExport)).Logger.Repository, memoryAppender); ActiveRecordStarter.CreateSchema(); PropertyBag["events"] = memoryAppender.GetEvents(); }
public static void Setup(string path) { var hierarchy = (Hierarchy)LogManager.GetRepository(); var patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; // patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; patternLayout.ActivateOptions(); var roller = new RollingFileAppender(); roller.AppendToFile = true; roller.File = path; roller.Layout = patternLayout; roller.MaxSizeRollBackups = 5; roller.MaximumFileSize = "2MB"; roller.RollingStyle = RollingFileAppender.RollingMode.Size; roller.StaticLogFileName = true; roller.ActivateOptions(); hierarchy.Root.AddAppender(roller); var memory = new MemoryAppender(); memory.ActivateOptions(); hierarchy.Root.AddAppender(memory); hierarchy.Root.Level = Level.Info; hierarchy.Configured = true; }
public void Setup() { var applicationDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PCoMD", "Log"); LogFilePath = Path.Combine(applicationDataDirectory, "PCoMD.xml"); var hierarchy = (Hierarchy) LogManager.GetRepository(); var patternLayout = new XmlLayoutSchemaLog4j(); patternLayout.LocationInfo = true; patternLayout.ActivateOptions(); var roller = new RollingFileAppender { AppendToFile = true, MaximumFileSize = "2MB", File = LogFilePath, PreserveLogFileNameExtension = true, MaxSizeRollBackups = 10, RollingStyle = RollingFileAppender.RollingMode.Size, Layout = patternLayout }; roller.ActivateOptions(); hierarchy.Root.AddAppender(roller); var memory = new MemoryAppender(); memory.ActivateOptions(); hierarchy.Root.AddAppender(memory); hierarchy.Root.Level = Level.Info; hierarchy.Configured = true; XmlConfigurator.Configure(hierarchy); }
/// <summary> /// Initializes a new instance of the <see cref="frmMain"/> class. /// </summary> public frmMain() { var cwh = ConsoleWindowHider.TryCreate(); if (cwh != null) cwh.Hide(); _logger = new MemoryAppender(); BasicConfigurator.Configure(_logger); InitializeComponent(); try { _cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); } catch (Exception ex) { const string errmsg = "Failed to create Processor performance counter: {0}"; if (log.IsErrorEnabled) log.ErrorFormat(errmsg, ex); _cpuCounter = null; } _serverThread = new Thread(ServerThread) { Name = "Server Thread", IsBackground = true }; }
public void TestThreadSafety() { ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString()); var memoryAppender = new MemoryAppender(); var patternLayout = new PatternLayout(); memoryAppender.Layout = patternLayout; memoryAppender.ActivateOptions(); BasicConfigurator.Configure(rep, memoryAppender); cThreadsRunning = cThreadsMax; var threads = Enumerable.Range(0, cThreadsMax) .Select(i => new Thread(LogMessages(rep.Name))) .ToList(); foreach (var thread in threads) { thread.Start(); } long cEventsRead = 0; while (cThreadsRunning > 0) { var events = memoryAppender.PopAllEvents(); cEventsRead += events.Length; } foreach (var thread in threads) { thread.Join(); } cEventsRead += memoryAppender.PopAllEvents().Length; Assert.AreEqual(cEventsExpected, cEventsRead, "Log events were lost."); }
protected override void OnTearDown() { if (memoryAppender != null) { var repository = (Hierarchy) LogManager.GetRepository(); repository.Root.RemoveAppender(memoryAppender); memoryAppender = null; } base.OnTearDown(); }
public void SetupFixture() { _log4NetMemoryLog = new MemoryAppender(); BasicConfigurator.Configure(_log4NetMemoryLog); GenericLibsBaseConfig.SetLoggerMethod = name => new Log4NetGenericLogger(name); _loggerA = GenericLibsBaseConfig.GetLogger("A"); _loggerB = GenericLibsBaseConfig.GetLogger("B"); }
public LogAttributeOnActionExecutedHttpGetFixture() { _memoryAppender = new MemoryAppender(); BasicConfigurator.Configure(_memoryAppender); _sut = new LogAttribute(); _context = ObjectMother.CreateActionActionExecutedContextFake(); Mock.Get(_context.HttpContext.Request).SetupGet(r => r.HttpMethod).Returns("GET"); }
public LogAttributeOnExceptionFixture() { _memoryAppender = new MemoryAppender(); BasicConfigurator.Configure(_memoryAppender); var sut = new LogAttribute(); var context = ObjectMother.CreateExceptionContextFake(); sut.OnException(context); }
private void SetUpLog(Level level) { _memoryAppender = new MemoryAppender(); Logger root = ((Hierarchy) LogManager.GetRepository()).Root; root.Level = level; root.AddAppender(_memoryAppender); root.Repository.Configured = true; }
public Log4NetLogManagerLoggingDisabledTests() { Log4NetLogManager.ProviderIsAvailableOverride = true; memoryAppender = new MemoryAppender(); memoryAppender.AddFilter(new DenyAllFilter()); BasicConfigurator.Configure(memoryAppender); sut = new Log4NetLogManager().GetLogger("Test"); }
public QuickThumbsHandler() { appender = new log4net.Appender.MemoryAppender(); log4net.Config.BasicConfigurator.Configure (appender); quickThumbs = new QuickThumbs(thumbWidth,thumbHeight); }
public void Setup() { _appender = new MemoryAppender(); BasicConfigurator.Configure(_appender); _chatBot = new ChatBot(); var filePath = $@"{Environment.CurrentDirectory}\AIML\ChatBotTests.aiml"; _chatBot.LoadAIML(filePath); }
public void RestoreDatabase_NotMongoConnection_LogAnError(MemoryAppender appender, MongoRestoreService sut) { //Arrange BasicConfigurator.Configure(appender); //Act sut.RestoreDatabase("sql"); //Assert appender.Events.Should().Contain(x => x.Level == Level.ERROR); }
public void InitialiseMockLogger() { var hierarchy = LogManager.GetRepository() as Hierarchy; mockLogger = hierarchy.Root.GetAppender("MemoryAppender") as MemoryAppender; if (mockLogger != null) { mockLogger.Clear(); } }
public LogSpy(string loggerName) { logger = (Logger)LogManager.GetLogger(loggerName).Logger; if (logger == null) throw new NullReferenceException(); prevLogLevel = logger.Level; logger.Level = Level.Debug; appender = new MemoryAppender(); logger.AddAppender(appender); }
public void ToArrayTest() { AppenderCollection appenderCollection = new AppenderCollection(); IAppender appender = new MemoryAppender(); appenderCollection.Add(appender); IAppender[] appenderArray = appenderCollection.ToArray(); Assert.AreEqual(1, appenderArray.Length); Assert.AreEqual(appender, appenderArray[0]); }
private MemoryAppender InitLog() { var appender = new log4net.Appender.MemoryAppender(); var filter = new log4net.Filter.LoggerMatchFilter { LoggerToMatch = typeof(Profiler).ToString(), AcceptOnMatch = true }; appender.AddFilter(filter); log4net.Config.BasicConfigurator.Configure(appender); return(appender); }
public void UsingCodeWithSpecific() { var appender = new MemoryAppender(); // This will configure log4net to log to the specified appender. // Will also call BasicConfigurator.Configure(memoryAppender); internally Configure.With() .Log4Net(appender) .DefineEndpointName("Snippets") .DefaultBuilder(); }
public void TestLogging() { // Set up a simple Log4Net configuration that logs in memory. var memAppend = new log4net.Appender.MemoryAppender(); #if NETCOREAPP1_0 var repository = LogManager.GetRepository(Assembly.GetEntryAssembly()); BasicConfigurator.Configure(repository, memAppend); #else BasicConfigurator.Configure(memAppend); #endif BrowseRequest br = new BrowseRequest(); br.Count = 20; br.Offset = 0; BrowseSelection colorSel = new BrowseSelection("mycolor"); colorSel.AddValue("yellow"); br.AddSelection(colorSel); BrowseSelection makeSel = new BrowseSelection("make"); makeSel.AddValue("rav4"); br.AddSelection(makeSel); FacetSpec spec = new FacetSpec(); spec.ExpandSelection = true; spec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc; spec.MaxCount = 15; br.SetFacetSpec("mycolor", spec); br.SetFacetSpec("id", spec); br.SetFacetSpec("make", spec); Directory ramIndexDir = CreateIndex(); using (DirectoryReader srcReader = DirectoryReader.Open(ramIndexDir)) { using (BoboMultiReader boboReader = BoboMultiReader.GetInstance(srcReader, _facetHandlers)) { using (BoboBrowser boboBrowser = new BoboBrowser(boboReader)) { using (BrowseResult result = boboBrowser.Browse(br)) { } } } } var events = memAppend.GetEvents(); Assert.AreEqual(3, events.Length); StringAssert.StartsWith("facetHandler loaded: id, took:", events[0].RenderedMessage); StringAssert.StartsWith("facetHandler loaded: make, took:", events[1].RenderedMessage); StringAssert.StartsWith("facetHandler loaded: mycolor, took:", events[2].RenderedMessage); }
public void Run_ValidCommand_LogOutputToDebug(MemoryAppender appender, ProcessRunner sut) { //Arrange BasicConfigurator.Configure(appender); //Act sut.Run("help", "dir"); //Assert appender.Events.Should().OnlyContain(x => x.Level == Level.DEBUG); }
static FormsLogInjectionModule() { //BasicConfigurator.Configure(); XmlConfigurator.Configure(); log.Debug("LOGGING Initialized"); Hierarchy h = LogManager.GetLoggerRepository() as Hierarchy; appender = h.Root.GetAppender("MemoryAppender") as MemoryAppender; if(appender==null) log.Error("MemoryAppender not found, form logging will not work."); }
/// <summary> /// Initializes a new instance of the <see cref="Log4netTests"/> class. /// </summary> static Log4netTests() { // Create the appender testAppender = new MemoryAppender { Name = "Unit Test Appender", Layout = new log4net.Layout.PatternLayout("%message"), Threshold = Level.Trace }; testAppender.ActivateOptions(); // Configure the default repository var root = ((Hierarchy)log4net.LogManager.GetRepository(Assembly.GetCallingAssembly())).Root; root.AddAppender(testAppender); root.Repository.Configured = true; }