public void ShouldNotEmitLogWhenNotEnabled() { var sink = new NLogHelper.TestSink(); var nlogSink = NLogHelper.CreateTarget(sink, DirectSubmissionLogLevel.Warning); var targetProxy = (global::NLog.Targets.Target) NLogCommon <LoggingConfiguration> .CreateNLogTargetProxy(nlogSink); var level = LogLevel.Info; var logEvent = new LogEventInfo(level, nameof(LoggerEnqueuesLogMessage), "This is some value"); var proxy = NLogHelper.GetLogEventProxy(logEvent); nlogSink.Write(proxy); sink.Events.Should().BeEmpty(); }
public void LoggerEnqueuesLogMessage() { var sink = new NLogHelper.TestSink(); var nlogSink = NLogHelper.CreateTarget(sink, DirectSubmissionLogLevel.Debug); var targetProxy = (global::NLog.Targets.Target) NLogCommon <LoggingConfiguration> .CreateNLogTargetProxy(nlogSink); var level = LogLevel.Error; var logEvent = new LogEventInfo(level, nameof(LoggerEnqueuesLogMessage), "This is some value"); var proxy = NLogHelper.GetLogEventProxy(logEvent); nlogSink.Write(proxy); sink.Events.Should().ContainSingle(); }
public void SerializesEventCorrectlyWhenUsingFallbackProperties() { var logEvent = GetLogEvent(); var log = NLogHelper.GetLogEventProxy(logEvent); var fallback = new Dictionary <object, object> { { "Value", 123 }, { "OtherProperty", 62 }, }; var wrapper = new LogEntry(log, properties: null, fallback); var formatter = LogSettingsHelper.GetFormatter(); var sb = new StringBuilder(); NLogLogFormatter.FormatLogEvent(formatter, sb, wrapper); var actual = sb.ToString(); var expected = @"{""@t"":""2021-09-13T10:40:57.0000000Z"",""@m"":""This is a test with a 123"",""@l"":""Debug"",""@x"":""System.InvalidOperationException: Oops, just a test!"",""Value"":123,""OtherProperty"":62,""@i"":""e5450052"",""ddsource"":""csharp"",""service"":""MyTestService"",""dd_env"":""integration_tests"",""dd_version"":""1.0.0"",""host"":""some_host""}"; actual.Should().Be(expected); }