Skip to content

Commit

Permalink
Add test for null EventName in FormattedMessage event
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhang committed Feb 13, 2020
1 parent 27ac3e5 commit f6bc94a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Logging/Logging.EventSource/test/EventSourceLoggerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,35 @@ public void Logs_Nothing_AfterDispose()
}
}

[Fact]
public void Logs_AsExpected_FormattedMessage_WithNullString()
{
using (var testListener = new TestEventListener())
{
var factory = CreateLoggerFactory();

var listenerSettings = new TestEventListener.ListenerSettings();
listenerSettings.Keywords = LoggingEventSource.Keywords.FormattedMessage;
listenerSettings.FilterSpec = null;
listenerSettings.Level = EventLevel.Verbose;
testListener.EnableEvents(listenerSettings);

LogStuff(factory);

var containsNullEventName = false;

foreach (var eventJson in testListener.Events)
{
if (eventJson.Contains(@"""__EVENT_NAME"":""FormattedMessage""") && eventJson.Contains(@"""EventName"":"""","))
{
containsNullEventName = true;
}
}

Assert.True(containsNullEventName, "EventName is supposed to be null but it isn't.");
}
}

private void LogStuff(ILoggerFactory factory)
{
var logger1 = factory.CreateLogger("Logger1");
Expand Down

0 comments on commit f6bc94a

Please sign in to comment.