public void TestExceptionRender()
        {
            try
            {
                // Throw the exception to give it a target site.
                throw new InvalidOperationException("Test Exception");
            }
            catch (InvalidOperationException e)
            {
                var logEvent = new LogEvent(
                    DateTimeOffset.UtcNow,
                    LogEventLevel.Error,
                    e,
                    new MessageTemplate(new MessageTemplateToken[0]),
                    new LogEventProperty[0]);
                var result = LogglySink.EventToJson(logEvent);
                var json   = JsonConvert.DeserializeObject <dynamic>(result);
                (json["Exception"]["TargetSite"] as object).Should().BeNull();
#if NET46
                (json["Exception"]["ClassName"].Value as string).Should().Be("System.InvalidOperationException");
#else
                (json["Exception"]["Type"].Value as string).Should().Be("System.InvalidOperationException");
#endif
            }
        }
Ejemplo n.º 2
0
        public void TestRender()
        {
            var logEvent = new LogEvent(DateTimeOffset.UtcNow,
                                        LogEventLevel.Debug, null, new MessageTemplate(Enumerable.Empty <MessageTemplateToken>()), new []
            {
                new LogEventProperty("test1", new ScalarValue("answer1")),
                new LogEventProperty("0", new ScalarValue("this should be missing")),
                new LogEventProperty("key", new ScalarValue("value"))
            });
            var result = LogglySink.EventToJson(logEvent);
            var json   = JsonConvert.DeserializeObject <dynamic>(result);

            (json["test1"].Value as string).Should().Be("answer1");
            bool hasZero = (json["0"] == null);

            hasZero.Should().Be(true);
            (json["key"].Value as string).Should().Be("value");
        }
Ejemplo n.º 3
0
        public void IncludeDiagnostics_WhenDisbled_DoesNotIncludeDiagnosticsEvent()
        {
            var logEvent = new LogEvent(DateTimeOffset.UtcNow,
                                        LogEventLevel.Debug, null, new MessageTemplate(Enumerable.Empty <MessageTemplateToken>()), new[]
            {
                new LogEventProperty("Field1", new ScalarValue("Value1")),
            });
            var result = new List <string> {
                LogglySink.EventToJson(logEvent)
            };

            var package = LogglySink.PackageContent(result, 1024, 5);

            var packageStringTask = package.ReadAsStringAsync();

            packageStringTask.Wait();
            var packageString = packageStringTask.Result;

            (result.Count == 1).Should().BeTrue();
            packageString.Contains("LogglyDiagnostics").Should().BeFalse();
        }