Skip to content

Commit

Permalink
Merge pull request #20 from altso/log-format
Browse files Browse the repository at this point in the history
Change log message format
  • Loading branch information
altso authored Apr 17, 2023
2 parents ae02635 + 4323ef0 commit 5cb3d11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void Log_includes_timestamp()
// ARRANGE
var logger = new LogDisplayLogger("Test", new LogDisplayLoggerOptions
{
TimestampFormat = "yyyy-MM-dd HH:mm:ss ",
TimestampFormat = "yyyy-MM-dd HH:mm:ss",
})
{
RecordLine = Mock.Of<Action<string, object[]>>(),
Expand Down Expand Up @@ -158,17 +158,4 @@ public void Log_does_not_show_LogDisplay(LogLevel level)
// ASSERT
Mock.Get(logger.Show).Verify(invoke => invoke(), Times.Never);
}

[Fact]
public void Log_throws_when_logLevel_is_wrong()
{
// ARRANGE
var logger = new LogDisplayLogger("Test");

// ACT & ASSERT
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
logger.Log((LogLevel)100, new Exception("TestException"), "TestMessage");
});
}
}
21 changes: 4 additions & 17 deletions Source/ExcelRna.Extensions.Logging/LogDisplayLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
builder.Append(" ");
}

builder.Append(GetLogLevelString(logLevel));
builder.Append(": ");
builder.Append("[");
builder.Append(logLevel);
builder.Append("] ");
builder.Append(_name);
builder.Append(" ");
builder.Append(": ");
builder.Append(message);

if (exception != null)
Expand All @@ -86,18 +87,4 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
Show();
}
}

private static string GetLogLevelString(LogLevel logLevel)
{
return logLevel switch
{
LogLevel.Trace => "trce",
LogLevel.Debug => "dbug",
LogLevel.Information => "info",
LogLevel.Warning => "warn",
LogLevel.Error => "fail",
LogLevel.Critical => "crit",
_ => throw new ArgumentOutOfRangeException(nameof(logLevel))
};
}
}

0 comments on commit 5cb3d11

Please sign in to comment.