Output options

edit

By default, an entry is its message, followed by its exception. Every way to create a logger accepts an optional XUnitLoggerOptions to add more:

ILogger<MyType> logger = XUnitLogger.CreateLogger<MyType>(testOutputHelper, new XUnitLoggerOptions
{
    IncludeLogLevel = true,
    IncludeCategory = true,
    IncludeScopes = true,
    TimestampFormat = "HH:mm:ss.fff",
    UseUtcTimestamp = true,
});

using (logger.BeginScope("TheScope"))
{
    logger.LogWarning("Something happened");
}

// 12:20:41.812 warn [MyNamespace.MyType] Something happened
//  => TheScope
PropertyDefaultEffect
TimestampFormatnullA date and time format string; the timestamp is written first. No timestamp when null
UseUtcTimestampfalseFormats the timestamp in UTC instead of the local time
IncludeLogLevelfalseWrites trce, dbug, info, warn, fail or crit
IncludeCategoryfalseWrites [CategoryName]
IncludeScopesfalseWrites the active scopes after the message, one per line, prefixed with =>

The segments are always in the same order: timestamp, level, category, message, scopes, then the exception on the next lines. The scopes come before the exception, so a long stack trace does not push them out of view.