public TestAppend ( log4net loggingEvent ) : void | ||
loggingEvent | log4net | |
Результат | void |
public void AppendTest() { var gelfAppender = new TestGelf4NetAppenderWrapper(); gelfAppender.Layout = new PatternLayout("%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n"); gelfAppender.Transport = new FakeTransport(); gelfAppender.ActivateOptions(); var data = new LoggingEventData { Domain = this.GetType().Name, Level = Level.Debug, LoggerName = "Tester", Message = "GrayLog4Net!!!", TimeStamp = DateTime.Now, UserName = "******" }; var logEvent = new LoggingEvent(data); gelfAppender.TestAppend(logEvent); var fakeTransport = gelfAppender.Transport as FakeTransport; if (fakeTransport != null) { var outputType = new { level = 0, short_message = ""}; var output = JsonConvert.DeserializeAnonymousType(fakeTransport.SentMessage, outputType); Assert.IsTrue(output.short_message.Contains("GrayLog4Net!!!")); Assert.AreEqual(Level.Debug, SeverityLevelConverter.SysLogLevelSeverityToLogLevelSeverity(output.level)); } }
public void AppendTestChunkMessage() { var gelfAppender = new TestGelf4NetAppenderWrapper(); gelfAppender.GrayLogServerHost = graylogServerHost; gelfAppender.MaxChunkSize = 50; gelfAppender.AdditionalFields = "nombre:pedro,apellido:jimenez"; gelfAppender.ActivateOptions(); //def logEvent = new LoggingEvent(this.GetType().Name, new Category('catName'), System.currentTimeMillis(), Priority.WARN, "Some Short Message", new Exception('Exception Message')) var data = new LoggingEventData { Domain = this.GetType().Name, Level = Level.Debug, LoggerName = "Big Tester", Message = LoremIpsum.Text, TimeStamp = DateTime.Now, UserName = "******" }; var logEvent = new LoggingEvent(data); logEvent.Properties["customProperty"] = "My Custom Property Woho"; gelfAppender.TestAppend(logEvent); }
public void AppendTest() { var gelfAppender = new TestGelf4NetAppenderWrapper(); gelfAppender.GrayLogServerHost = graylogServerHost; gelfAppender.ActivateOptions(); //def logEvent = new LoggingEvent(this.GetType().Name, new Category('catName'), System.currentTimeMillis(), Priority.WARN, "Some Short Message", new Exception('Exception Message')) var data = new LoggingEventData { Domain = this.GetType().Name, Level = Level.Debug, LoggerName = "Tester", Message = "GrayLog4Net!!!", TimeStamp = DateTime.Now, UserName = "******" }; var logEvent = new LoggingEvent(data); gelfAppender.TestAppend(logEvent); }
public void AppendTest() { var gelfAppender = new TestGelf4NetAppenderWrapper(); gelfAppender.GrayLogServerHost = graylogServerHost; gelfAppender.ActivateOptions(); //def logEvent = new LoggingEvent(this.GetType().Name, new Category('catName'), System.currentTimeMillis(), Priority.WARN, "Some Short Message", new Exception('Exception Message')) var data = new LoggingEventData { Domain = this.GetType().Name, Level = Level.Debug, LoggerName = "Tester", Message = "GrayLog4Net!!!", TimeStamp = DateTime.Now, UserName = "******" }; var logEvent = new LoggingEvent(data); gelfAppender.TestAppend(logEvent); }
public void AppendTestChunkMessage() { var gelfAppender = new TestGelf4NetAppenderWrapper(); gelfAppender.RemoteAddress = graylogServerHost; gelfAppender.AdditionalFields = "nombre:pedro,apellido:jimenez"; gelfAppender.ActivateOptions(); //def logEvent = new LoggingEvent(this.GetType().Name, new Category('catName'), System.currentTimeMillis(), Priority.WARN, "Some Short Message", new Exception('Exception Message')) var data = new LoggingEventData { Domain = this.GetType().Name, Level = Level.Debug, LoggerName = "Big Tester", Message = LoremIpsum.Text, TimeStamp = DateTime.Now, UserName = "******" }; var logEvent = new LoggingEvent(data); logEvent.Properties["customProperty"] = "My Custom Property Woho"; gelfAppender.TestAppend(logEvent); }
public void AppendTestChunkMessage() { var gelfAppender = new TestGelf4NetAppenderWrapper(); gelfAppender.Layout = new PatternLayout("%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n"); gelfAppender.Transport = BuildTestUdpTransport(); gelfAppender.MaxChunkSize = 50; gelfAppender.AdditionalFields = "nombre:pedro,apellido:jimenez"; gelfAppender.ActivateOptions(); var data = new LoggingEventData { Domain = this.GetType().Name, Level = Level.Debug, LoggerName = "Big Tester", Message = LoremIpsum.Text, TimeStamp = DateTime.Now, UserName = "******" }; var logEvent = new LoggingEvent(data); logEvent.Properties["customProperty"] = "My Custom Property Woho"; gelfAppender.TestAppend(logEvent); }
public void AppendWithCustomPerMessageProperties() { var testAppender = new TestGelf4NetAppenderWrapper(); testAppender.RemoteAddress = "127.0.0.1"; testAppender.AdditionalFields = "global1:foo,global2:bar"; testAppender.ActivateOptions(); var data = new LoggingEventData { Domain = GetType().Name, Level = Level.Debug, LoggerName = "PerMessageProperties", TimeStamp = DateTime.UtcNow, UserName = "******" }; var messageObject = new CustomMessage { ShortMessage = "This is a custom message to test per-message fields and overrides.", CustomFields = new Dictionary<string, string> { { "message1", "baz" }, { "message2", "baf" }, { "message3", "woohoo" } } }; data.Message = messageObject.ToString(); var logEvent = new LoggingEvent(GetType(), new Hierarchy(), data.LoggerName, data.Level, messageObject, new InvalidOperationException("This is a test exception!")); testAppender.TestAppend(logEvent); JObject gelfMessage = JObject.Parse(testAppender.LastMessage); Assert.AreEqual(gelfMessage["_global1"].ToString(), "foo"); Assert.AreEqual(gelfMessage["_global2"].ToString(), "bar"); Assert.AreEqual(gelfMessage["_message1"].ToString(), "baz"); Assert.AreEqual(gelfMessage["_message2"].ToString(), "baf"); Assert.AreEqual(gelfMessage["_message3"].ToString(), "woohoo"); Assert.AreEqual(messageObject.ShortMessage, gelfMessage["short_message"].ToString()); }