public void WrapperRefTest() { LoggingConfiguration c = CreateConfigurationFromString(@" <nlog> <targets> <target name='c' type='Debug' layout='${message}' /> <wrapper name='a' type='AsyncWrapper'> <target-ref name='c' /> </wrapper> <wrapper-target name='b' type='BufferingWrapper' bufferSize='19'> <wrapper-target-ref name='a' /> </wrapper-target> </targets> </nlog>"); Assert.IsNotNull(c.FindTargetByName("a")); Assert.IsNotNull(c.FindTargetByName("b")); Assert.IsNotNull(c.FindTargetByName("c")); Assert.IsInstanceOfType(typeof(BufferingTargetWrapper), c.FindTargetByName("b")); Assert.IsInstanceOfType(typeof(AsyncTargetWrapper), c.FindTargetByName("a")); Assert.IsInstanceOfType(typeof(DebugTarget), c.FindTargetByName("c")); BufferingTargetWrapper btw = c.FindTargetByName("b") as BufferingTargetWrapper; AsyncTargetWrapper atw = c.FindTargetByName("a") as AsyncTargetWrapper; DebugTarget dt = c.FindTargetByName("c") as DebugTarget; Assert.AreSame(atw, btw.WrappedTarget); Assert.AreSame(dt, atw.WrappedTarget); Assert.AreEqual(19, btw.BufferSize); }
public void Stop() { if (!_running) { return; } _pc = 0; _events.DebugLeave -= EventsOnDebugLeave; _events.DebugEnter -= EventsOnDebugEnter; _events.MemoryChanged -= EventsOnMemoryChanged; _events.Stop(_debugTarget); _server.UnknownData -= ServerOnUnknownData; _server.DebuggerAttached -= ServerDebuggerAttached; // Start the debug server _server.Stop(); _debugTarget = null; _target = null; _state = State.None; DebugStateChanged?.Invoke(); _running = false; }
public static void ClassInitialize(TestContext context) { var config = LogManager.Configuration; target = config.FindTargetByName("unitTest") as DebugTarget; logger = new NLogger(); }
public void CreatingFromConfigSetsIntervalCorrectly() { LoggingConfiguration config = CreateConfigurationFromString(@" <nlog> <targets> <wrapper-target name='limiting' type='LimitingWrapper' interval='1:2:5:00'> <target name='debug' type='Debug' layout='${message}' /> </wrapper-target> </targets> <rules> <logger name='*' level='Debug' writeTo='limiting' /> </rules> </nlog>"); LimitingTargetWrapper limitingWrapper = (LimitingTargetWrapper)config.FindTargetByName("limiting"); DebugTarget debugTarget = (DebugTarget)config.FindTargetByName("debug"); Assert.NotNull(limitingWrapper); Assert.NotNull(debugTarget); Assert.Equal(1000, limitingWrapper.MessageLimit); Assert.Equal(TimeSpan.FromDays(1) + TimeSpan.FromHours(2) + TimeSpan.FromMinutes(5), limitingWrapper.Interval); LogManager.Configuration = config; ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", "a"); }
public void Start(ITransport transport) { if (_running) { return; } _state = State.None; _target = ATServiceProvider.GetService <STargetService, ITargetService>(); _debugTarget = _target.GetCurrentTarget(); _pc = 0; _ramSpace = _debugTarget.Device.GetAddressSpace("data"); _events.DebugLeave += EventsOnDebugLeave; _events.DebugEnter += EventsOnDebugEnter; _events.MemoryChanged += EventsOnMemoryChanged; _events.Start(_debugTarget); _server.SetTransport(transport); _server.UnknownData += ServerOnUnknownData; _server.DebuggerAttached += ServerDebuggerAttached; // Start the debug server _server.Start(); _output.Activate(Output.SDSerialOutputPane); DebugStateChanged?.Invoke(); _running = true; }
public void TurningPoolingOnShouldResultInObjectsBeingReused() { var configuration = CreateConfigurationFromString(@" <nlog throwExceptions='true'> <pooling enabled=""true"" autoIncreasePoolSizes=""true"" prefillPools=""false"" outputPoolStatisticsInLogFiles=""false"" estimatedMaxMessageSize=""2048"" estimatedLogEventsPerSecond=""1"" /> <targets> <target name='d' type='Debug' layout='${message}' /> </targets> <rules> <logger name='*' writeTo='d' minLevel=""Trace""> </logger> </rules> </nlog>"); LogManager.Configuration = configuration; var list = this.WarmUpPool(configuration, 1); var logger = LogManager.GetLogger("test"); logger.Info("Test"); DebugTarget target = (DebugTarget)configuration.FindTargetByName("d"); var loggedEvent = target.LastLogEvent; LogManager.Configuration.FlushAllTargets(ex => { }); Assert.True(list.Contains(loggedEvent), " Not same log event, which is unexpected, since we only have one target and not prefilling"); }
public void TurningOffPoolingAfterStartupShouldEmptyPools() { LogManager.Configuration = CreateConfigurationFromString(Poolingenabled); var list = this.WarmUpPool(LogManager.Configuration, 1); var firstLogEvent = LogManager.Configuration.PoolFactory.Get <LogEventInfoPool, LogEventInfo>().Get(); LogManager.Configuration.PoolFactory.Get <LogEventInfoPool, LogEventInfo>().PutBack(firstLogEvent); var logger = LogManager.GetLogger("test"); logger.Info("Test"); DebugTarget target = (DebugTarget)LogManager.Configuration.FindTargetByName("d"); var loggedEvent = target.LastLogEvent; LogManager.Flush(Console.WriteLine); var pool = LogManager.Configuration.PoolFactory.Get <LogEventInfoPool, LogEventInfo>(); // DebugTarget keeps one object from the pool, so we have to add one Assert.True(1 <= pool.ObjectsInPool + 1); Assert.True(list.Contains(loggedEvent), " Not Same log event, which is unexpected, since pooling is turned on"); LogManager.Configuration = CreateConfigurationFromString(PoolingDisabled); pool = LogManager.Configuration.PoolFactory.Get <LogEventInfoPool, LogEventInfo>(); Assert.Equal(0, pool.ObjectsInPool); }
public void TurningOffPoolingAfterStartupShouldStopUsingPooledObjects() { LogManager.Configuration = CreateConfigurationFromString(Poolingenabled); var list = this.WarmUpPool(LogManager.Configuration, 1); var firstLogEvent = LogManager.Configuration.PoolFactory.Get <LogEventInfoPool, LogEventInfo>().Get(); LogManager.Configuration.PoolFactory.Get <LogEventInfoPool, LogEventInfo>().PutBack(firstLogEvent); var logger = LogManager.GetLogger("test"); logger.Info("Test"); DebugTarget target = (DebugTarget)LogManager.Configuration.FindTargetByName("d"); var loggedEvent = target.LastLogEvent; Assert.True(list.Contains(loggedEvent), " Not Same log event, which is unexpected, since pooling is turned on"); LogManager.Configuration = CreateConfigurationFromString(PoolingDisabled); LogManager.GetLogger("test"); logger.Info("Test"); target = (DebugTarget)LogManager.Configuration.FindTargetByName("d"); loggedEvent = target.LastLogEvent; Assert.False(list.Contains(loggedEvent), " Not Same log event, which is unexpected, since pooling is turned off"); }
public void WrapperTest() { XmlDocument doc = new XmlDocument(); doc.LoadXml(@" <nlog> <targets> <target name='b' type='BufferingWrapper' bufferSize='19'> <target name='a' type='AsyncWrapper'> <target name='c' type='Debug' layout='${message}' /> </target> </target> </targets> </nlog>"); LoggingConfiguration c = new XmlLoggingConfiguration(doc.DocumentElement, null); Assert.IsNotNull(c.FindTargetByName("a")); Assert.IsNotNull(c.FindTargetByName("b")); Assert.IsNotNull(c.FindTargetByName("c")); Assert.IsInstanceOfType(typeof(BufferingTargetWrapper), c.FindTargetByName("b")); Assert.IsInstanceOfType(typeof(AsyncTargetWrapper), c.FindTargetByName("a")); Assert.IsInstanceOfType(typeof(DebugTarget), c.FindTargetByName("c")); BufferingTargetWrapper btw = c.FindTargetByName("b") as BufferingTargetWrapper; AsyncTargetWrapper atw = c.FindTargetByName("a") as AsyncTargetWrapper; DebugTarget dt = c.FindTargetByName("c") as DebugTarget; Assert.AreSame(atw, btw.WrappedTarget); Assert.AreSame(dt, atw.WrappedTarget); Assert.AreEqual(19, btw.BufferSize); }
public static void ConfigureLogging(string testTag, bool includeFile = true) { var config = new LoggingConfiguration(); var debugTarget = new DebugTarget($"{testTag}"); debugTarget.Layout = "${message}"; config.AddTarget(debugTarget); config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, debugTarget)); var consoleTarget = new ConsoleTarget($"{testTag}_C"); consoleTarget.Layout = "${message}"; config.AddTarget(consoleTarget); config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget)); if (includeFile) { var fileTarget = new FileTarget(); config.AddTarget("file", fileTarget); fileTarget.FileName = Path.Combine(BaseDir, $"test_{testTag}.log"); fileTarget.Layout = "${logger}: ${message}"; fileTarget.DeleteOldFileOnStartup = true; config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget)); } LogManager.Configuration = config; }
public void WrapperRefTest() { LoggingConfiguration c = XmlLoggingConfiguration.CreateFromXmlString(@" <nlog> <targets> <target name='c' type='Debug' layout='${message}' /> <wrapper name='a' type='AsyncWrapper'> <target-ref name='c' /> </wrapper> <wrapper-target name='b' type='BufferingWrapper' bufferSize='19'> <wrapper-target-ref name='a' /> </wrapper-target> </targets> </nlog>"); Assert.NotNull(c.FindTargetByName("a")); Assert.NotNull(c.FindTargetByName("b")); Assert.NotNull(c.FindTargetByName("c")); Assert.IsType <BufferingTargetWrapper>(c.FindTargetByName("b")); Assert.IsType <AsyncTargetWrapper>(c.FindTargetByName("a")); Assert.IsType <DebugTarget>(c.FindTargetByName("c")); BufferingTargetWrapper btw = c.FindTargetByName("b") as BufferingTargetWrapper; AsyncTargetWrapper atw = c.FindTargetByName("a") as AsyncTargetWrapper; DebugTarget dt = c.FindTargetByName("c") as DebugTarget; Assert.Same(atw, btw.WrappedTarget); Assert.Same(dt, atw.WrappedTarget); Assert.Equal(19, btw.BufferSize); }
private void InitLogger() { var config = new LoggingConfiguration(); var logfile = new FileTarget("logfile") { FileName = Path.Combine(FileSystem.CacheDirectory, AppConstants.LogFileName), AutoFlush = true, ArchiveEvery = FileArchivePeriod.Month }; var debugTarget = new DebugTarget("console"); #if !DEBUG // Configure AppCenter var appCenterTarget = new AppCenterTarget("appcenter") { AppSecret = ConfigurationManager.AppSettings["IosAppcenterSecret"] }; config.AddRule(LogLevel.Debug, LogLevel.Fatal, appCenterTarget); #endif config.AddRule(LogLevel.Info, LogLevel.Fatal, debugTarget); config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); LogManager.Configuration = config; }
public void TurningPoolingOffShouldResultInObjectsNotBeingReused() { var configuration = CreateConfigurationFromString(@" <nlog throwExceptions='true'> <pooling enabled=""false"" autoIncreasePoolSizes=""false"" prefillPools=""false"" outputPoolStatisticsInLogFiles=""false"" estimatedMaxMessageSize=""2048"" estimatedLogEventsPerSecond=""100"" /> <targets> <target name='d' type='Debug' layout='${message}' /> </targets> <rules> <logger name='*' writeTo='d' minLevel=""Trace""> </logger> </rules> </nlog>"); var firstLogEvent = configuration.PoolFactory.Get <LogEventInfoPool, LogEventInfo>().Get(); configuration.PoolFactory.Get <LogEventInfoPool, LogEventInfo>().PutBack(firstLogEvent); LogManager.Configuration = configuration; var logger = LogManager.GetLogger("test"); logger.Info("Test"); DebugTarget target = (DebugTarget)configuration.FindTargetByName("d"); var loggedEvent = target.LastLogEvent; Assert.True(firstLogEvent != loggedEvent, " Same log event, which is unexpected, since pooling is turned off"); }
public void SimpleTest2() { XmlDocument doc = new XmlDocument(); doc.LoadXml(@" <nlog> <targets> <target name='d' type='Debug' layout='${message:padding=10} ${level}' /> </targets> </nlog>"); LoggingConfiguration c = new XmlLoggingConfiguration(doc.DocumentElement, null); DebugTarget t = c.FindTargetByName("d") as DebugTarget; Assert.IsNotNull(t); Assert.AreEqual(t.Name, "d"); Assert.AreEqual("${message:padding=10} ${level}", t.Layout); Layout l = t.CompiledLayout as Layout; Assert.IsNotNull(l); Assert.AreEqual(3, l.Renderers.Length); Assert.IsInstanceOfType(typeof(MessageLayoutRenderer), l.Renderers[0]); Assert.IsInstanceOfType(typeof(LiteralLayoutRenderer), l.Renderers[1]); Assert.IsInstanceOfType(typeof(LevelLayoutRenderer), l.Renderers[2]); Assert.AreEqual(10, l.Renderers[0].Padding); }
private DebugTarget GetDebugTarget(LogLevel level) { DebugTarget debugTarget = new DebugTarget(); debugTarget.Layout = "${message}"; SimpleConfigurator.ConfigureForTargetLogging(debugTarget, level); return(debugTarget); }
public static Target Target() { var debugTarget = new DebugTarget(); debugTarget.Name = "debuggerLog"; debugTarget.Layout = "${longdate}|${pad:padding=5:inner=${level:uppercase=true}}|${message}"; return(debugTarget); }
public NLogTracerWriterTests() { // setup writer under test _writer = new NLogTraceWriter(); // setup debug logging target _debugTarget = new DebugTarget { Layout = "${message}" }; SimpleConfigurator.ConfigureForTargetLogging(_debugTarget, LogLevel.Info); }
public void Error_should_log_info_level_messages() { // Arrange DebugTarget debugTarget = GetDebugTarget(LogLevel.Error); // Act Log.Error("Test error message"); // Assert Assert.That(debugTarget.LastMessage, Is.EqualTo("Test error message")); }
public void Warn_should_log_info_level_messages() { // Arrange DebugTarget debugTarget = GetDebugTarget(LogLevel.Warn); // Act Log.Warn("Test warn message"); // Assert Assert.That(debugTarget.LastMessage, Is.EqualTo("Test warn message")); }
public void Debug_should_log_debug_level_messages() { // Arrange DebugTarget debugTarget = GetDebugTarget(LogLevel.Debug); // Act Log.Debug("Test debug message"); // Assert Assert.That(debugTarget.LastMessage, Is.EqualTo("Test debug message")); }
/// <summary> /// This is only for attached debugging tools /// </summary> private void ConfigureDebugLogging(LoggingConfiguration configuration) { if (!EnableDebugLogging) { return; } var debugTarget = new DebugTarget("CoreBaseLogDebugLogger"); configuration.AddTarget(debugTarget); configuration.LoggingRules.Add(new LoggingRule("*", DebugLogLevel, debugTarget)); }
public void Information_should_log_info_level_messages() { // Arrange DebugTarget debugTarget = GetDebugTarget(LogLevel.Info); // Act Log.Information("Test info message"); // Assert Assert.That(debugTarget.LastMessage, Is.EqualTo("Test info message")); }
static VariableLayoutRendererTests() { var t1 = new DebugTarget { Name = "t1", Layout = "${message}|${var:var1:default=x}" }; _mockConfig.AddTarget(t1); _mockConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, t1)); _mockConfig.Variables["var1"] = "my-mocking-manager"; }
public ManualFlushWrapperTest() { var loggingConfiguration = new LoggingConfiguration(); debugTarget = new DebugTarget(); manualFlushTarget = new ManualFlushWrapper { WrappedTarget = debugTarget }; loggingConfiguration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, manualFlushTarget)); loggingConfiguration.AddTarget("Manual", manualFlushTarget); LogManager.Configuration = loggingConfiguration; }
public WebApiTraceRendererTests() { EnsureLayoutRendersSetup.Please(); // setup writer under test _writer = new NLogTraceWriter(); // setup debug logging target _debugTarget = new DebugTarget { Layout = "${message}" }; SimpleConfigurator.ConfigureForTargetLogging(_debugTarget, LogLevel.Info); }
public void Attach(IDebuggable dbg) { _emulator = dbg; _emulator.Breakpoint += OnBreakpoint; // For memory read/write breakpoints: busManager.Events.SubscribeWrMem(0x0000, 0x0000, OnMemoryWrite); busManager.Events.SubscribeRdMem(0x0000, 0x0000, OnMemoryRead); var bridge = new DebugTarget(_emulator, this); server = new GDBNetworkServer(bridge, Port); }
public void LogMessageWithNestedObjects_UserModifiedRecursionLimit() { //Arrange // For this one-off test, need to re-do the logging configuration to override what is done in setup var target = new DebugTarget("customAttributeTarget"); var layout = new NewRelicJsonLayout(() => _testAgent); layout.MaxRecursionLimit = 3; target.Layout = layout; var config = new LoggingConfiguration(); config.AddTarget(target); config.AddRuleForAllLevels(target); LogManager.Configuration = config; var logger = LogManager.GetLogger("customAttributeLogger"); var alice = new Person { Name = "Alice", Manager = null }; var bob = new Person { Name = "Bob", Manager = alice }; var charlie = new Person { Name = "Charlie", Manager = bob }; var messageTemplate = "Person = {person}"; var formattedMessage = "Person = Charlie"; //Act logger.Info(messageTemplate, charlie); var loggedMessage = target.LastMessage; var resultsDictionary = TestHelpers.DeserializeOutputJSON(loggedMessage); //Assert Asserts.KeyAndValueMatch(resultsDictionary, NewRelicLoggingProperty.MessageText.GetOutputName(), formattedMessage); Asserts.KeyAndValueMatch(resultsDictionary, NewRelicLoggingProperty.MessageTemplate.GetOutputName(), messageTemplate); Assert.IsTrue(resultsDictionary.ContainsKey(UserPropertiesKey)); Asserts.KeyAndValueMatch(resultsDictionary, UserPropertiesKey, JsonValueKind.Object); var userPropertiesDict = TestHelpers.DeserializeOutputJSON(resultsDictionary[UserPropertiesKey].ToString()); Asserts.KeyAndValueMatch(userPropertiesDict, "person", JsonValueKind.Object); var userPropValDict = TestHelpers.DeserializeOutputJSON(userPropertiesDict["person"].ToString()); Asserts.KeyAndValueMatch(userPropValDict, "Name", "Charlie"); Asserts.KeyAndValueMatch(userPropValDict, "Manager", JsonValueKind.Object); }
public void Stop(DebugTarget target) { var channel = target.KnownTool.GetChannel(); var services = channel.GetRemoteServices().ToList(); services.ForEach(service => channel.RemoveEventListener(service, this)); _state = State.Stopping; _server.DebuggerAttached -= Server_DebuggerAttached; _suspendBarrier.Reset(); _suspendBarrier.Signal(2); _notifyDebugEnterThread.Join(); _state = State.None; }
public void LevelOff_NoLog() { // Arrange var target = new DebugTarget(); target.Layout = _LAYOUT; NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Off); var sut = new WD.Logging.NLogLoggerAdapter <NLogAdapterTests>(); // Act ExecuteLogs(sut); // Assert target.Counter.Should().Be(0); }
public void CompoundRefTest() { LoggingConfiguration c = CreateConfigurationFromString(@" <nlog> <targets> <target name='d1' type='Debug' layout='${message}1' /> <target name='d2' type='Debug' layout='${message}2' /> <target name='d3' type='Debug' layout='${message}3' /> <target name='d4' type='Debug' layout='${message}4' /> <compound-target name='rr' type='RoundRobinGroup'> <target-ref name='d1' /> <target-ref name='d2' /> <target-ref name='d3' /> <target-ref name='d4' /> </compound-target> </targets> </nlog>"); Assert.IsNotNull(c.FindTargetByName("rr")); Assert.IsNotNull(c.FindTargetByName("d1")); Assert.IsNotNull(c.FindTargetByName("d2")); Assert.IsNotNull(c.FindTargetByName("d3")); Assert.IsNotNull(c.FindTargetByName("d4")); Assert.IsInstanceOfType(typeof(RoundRobinGroupTarget), c.FindTargetByName("rr")); Assert.IsInstanceOfType(typeof(DebugTarget), c.FindTargetByName("d1")); Assert.IsInstanceOfType(typeof(DebugTarget), c.FindTargetByName("d2")); Assert.IsInstanceOfType(typeof(DebugTarget), c.FindTargetByName("d3")); Assert.IsInstanceOfType(typeof(DebugTarget), c.FindTargetByName("d4")); RoundRobinGroupTarget rr = c.FindTargetByName("rr") as RoundRobinGroupTarget; DebugTarget d1 = c.FindTargetByName("d1") as DebugTarget; DebugTarget d2 = c.FindTargetByName("d2") as DebugTarget; DebugTarget d3 = c.FindTargetByName("d3") as DebugTarget; DebugTarget d4 = c.FindTargetByName("d4") as DebugTarget; Assert.AreEqual(4, rr.Targets.Count); Assert.AreSame(d1, rr.Targets[0]); Assert.AreSame(d2, rr.Targets[1]); Assert.AreSame(d3, rr.Targets[2]); Assert.AreSame(d4, rr.Targets[3]); Assert.AreEqual(((SimpleLayout)d1.Layout).Text, "${message}1"); Assert.AreEqual(((SimpleLayout)d2.Layout).Text, "${message}2"); Assert.AreEqual(((SimpleLayout)d3.Layout).Text, "${message}3"); Assert.AreEqual(((SimpleLayout)d4.Layout).Text, "${message}4"); }