/// <summary> /// Resets the text of the test log (presuming that there is only one). /// </summary> public static void ResetTestLog( this LogWriter logger) => logger.Configure( logConfig => (logConfig .AllTraceListeners .OfType <TestTraceListener>() .FirstOrDefault())?.Reset());
/// <summary> /// Gets the text of the test log so far (presuming that there is only one). /// </summary> public static string GetTestLogText( this LogWriter logger, bool resetTestLog = false) { string logText = null; logger.Configure( logConfig => { var testLog = logConfig .AllTraceListeners .OfType <TestTraceListener>() .FirstOrDefault(); if (testLog == null) { return; } logText = testLog.LogText; if (resetTestLog) { testLog.Reset(); } }); return(logText); }
public void ReconfigureTraceEnabled() { var config = new LoggingConfiguration(); config.IsTracingEnabled = false; var logger = new LogWriter(config); // Is it false? logger.Configure(cfg => Assert.IsFalse(cfg.UseImpersonation)); // Toggle logger.Configure(cfg => cfg.IsTracingEnabled = true); // Did it change? logger.Configure(cfg => Assert.IsTrue(cfg.IsTracingEnabled)); }
public void ReconfigureImpersonation() { var config = new LoggingConfiguration(); config.UseImpersonation = false; var logger = new LogWriter(config); // Is it false? logger.Configure(cfg => Assert.IsFalse(cfg.UseImpersonation)); // Use impersonation logger.Configure(cfg => cfg.UseImpersonation = true); // Did it change? logger.Configure(cfg => Assert.IsTrue(cfg.UseImpersonation)); }
public void ReconfigureIsLoggingEnabled() { var config = new LoggingConfiguration(); Assert.IsTrue(config.IsLoggingEnabled); var logger = new LogWriter(config); Assert.IsTrue(logger.IsLoggingEnabled()); // Disable logging logger.Configure(cfg => cfg.IsLoggingEnabled = false); Assert.IsFalse(logger.IsLoggingEnabled()); }
static void ReplacePriorityFilter(int maximumPriority) { defaultWriter.Configure(cfg => { cfg.Filters.Clear(); // Category Filters ICollection <string> categories = new List <string>(); categories.Add("BlockedByFilter"); // Log Filters var priorityFilter = new PriorityFilter("Priority Filter", 2, maximumPriority); var logEnabledFilter = new LogEnabledFilter("LogEnabled Filter", true); var categoryFilter = new CategoryFilter("Category Filter", categories, CategoryFilterMode.AllowAllExceptDenied); cfg.Filters.Add(priorityFilter); cfg.Filters.Add(logEnabledFilter); cfg.Filters.Add(categoryFilter); }); }
public void ReconfigureDisposesUnusedListeners() { var traceListener = new MockDisposableTraceListener(); var config = new LoggingConfiguration(); config.AddLogSource("General", traceListener); var logWriter = new LogWriter(config); logWriter.Configure((cfg) => { cfg.LogSources.Clear(); cfg.AddLogSource("New", new DefaultTraceListener()); }); Assert.AreEqual(1, traceListener.DisposedCalls); }
public void ReconfigureDoesNotDisposeListenersStillUsedInSpecialSources() { var traceListener = new MockDisposableTraceListener(); var config = new LoggingConfiguration(); config.AddLogSource("General", traceListener); var logWriter = new LogWriter(config); logWriter.Configure((cfg) => { cfg.LogSources.Clear(); cfg.AddLogSource("New", new DefaultTraceListener()); cfg.SpecialSources.AllEvents.Listeners.Add(traceListener); }); Assert.AreEqual(0, traceListener.DisposedCalls); }
public void ReconfigureDoesNotDisposeListenersStillUsedInSpecialSources() { var traceListener = new MockDisposableTraceListener(); var config = new LoggingConfiguration(); config.AddLogSource("General", traceListener); var logWriter = new LogWriter(config); logWriter.Configure((cfg) => { cfg.LogSources.Clear(); cfg.AddLogSource("New", new DefaultTraceListener()); cfg.SpecialSources.AllEvents.Listeners.Add(traceListener); }); Assert.AreEqual(0, traceListener.DisposedCalls); }
public void ReconfigureDisposesUnusedListeners() { var traceListener = new MockDisposableTraceListener(); var config = new LoggingConfiguration(); config.AddLogSource("General", traceListener); var logWriter = new LogWriter(config); logWriter.Configure((cfg) => { cfg.LogSources.Clear(); cfg.AddLogSource("New", new DefaultTraceListener()); }); Assert.AreEqual(1, traceListener.DisposedCalls); }
public void ReconfigureIsLoggingEnabled() { var config = new LoggingConfiguration(); Assert.IsTrue(config.IsLoggingEnabled); var logger = new LogWriter(config); Assert.IsTrue(logger.IsLoggingEnabled()); // Disable logging logger.Configure(cfg => cfg.IsLoggingEnabled = false); Assert.IsFalse(logger.IsLoggingEnabled()); }
public void ReconfigureTraceEnabled() { var config = new LoggingConfiguration(); config.IsTracingEnabled = false; var logger = new LogWriter(config); // Is it false? logger.Configure(cfg => Assert.IsFalse(cfg.UseImpersonation)); // Toggle logger.Configure(cfg => cfg.IsTracingEnabled = true); // Did it change? logger.Configure(cfg => Assert.IsTrue(cfg.IsTracingEnabled)); }
public void ReconfigureImpersonation() { var config = new LoggingConfiguration(); config.UseImpersonation = false; var logger = new LogWriter(config); // Is it false? logger.Configure(cfg => Assert.IsFalse(cfg.UseImpersonation)); // Use impersonation logger.Configure(cfg => cfg.UseImpersonation = true); // Did it change? logger.Configure(cfg => Assert.IsTrue(cfg.UseImpersonation)); }