Skip to content

Commit

Permalink
MicrosoftConsoleLayoutRenderer - Fixed IndexOutOfRangeException when …
Browse files Browse the repository at this point in the history
…large EventID (#570)
  • Loading branch information
mickelsonmichael authored Feb 5, 2022
1 parent d830e8b commit cfb772e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static string ConvertEventId(int eventId)
{
if (eventId == 0)
return "0";
else if (eventId > 0 || eventId < EventIdMapper.Length)
else if (eventId > 0 && eventId < EventIdMapper.Length)
return EventIdMapper[eventId];
else
return eventId.ToString(System.Globalization.CultureInfo.InvariantCulture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ public void MicrosoftConsoleLayoutRenderer_ExceptionEvent()
Assert.Equal($"fail: MyLogger[{eventId}]{Environment.NewLine} Alert 42{Environment.NewLine}{exception}", result);
}

[Fact]
public void MicrosoftConsoleLayoutRenderer_OutOfMapperBoundsEventId()
{
var layoutRenderer = new MicrosoftConsoleLayoutRenderer();
var exception = new ArgumentException("Test");
var eventId = 500;
var result = layoutRenderer.Render(new LogEventInfo(LogLevel.Error, "MyLogger", null, "Alert {EventId_Id}", new object[] { eventId }, exception));
Assert.Equal($"fail: MyLogger[{eventId}]{Environment.NewLine} Alert 500{Environment.NewLine}{exception}", result);
}


[Fact]
public void MicrosoftConsoleLayoutRenderer_TimestampFormat()
{
Expand Down

0 comments on commit cfb772e

Please sign in to comment.