Skip to content

Commit

Permalink
在切换线程前,先把日志时间给捕获了,避免日志时间与实际不符
Browse files Browse the repository at this point in the history
  • Loading branch information
walterlv committed Aug 22, 2024
1 parent 4bc04ff commit 573f89c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/dotnetCampus.Logger/Writers/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
return;
}

var traceTag = TraceTag;
var debugTag = DebugTag;
var informationTag = InformationTag;
var warningTag = WarningTag;
var errorTag = ErrorTag;
var criticalTag = CriticalTag;
LogCore(logLevel, exception, message, m => logLevel switch
{
LogLevel.Trace => $"{TraceTag} {TraceText}{m}{Reset}",
LogLevel.Debug => $"{DebugTag} {DebugText}{m}{Reset}",
LogLevel.Information => $"{InformationTag} {InformationText}{m}{Reset}",
LogLevel.Warning => $"{WarningTag} {WarningText}{m}{Reset}",
LogLevel.Error => $"{ErrorTag} {ErrorText}{m}{Reset}",
LogLevel.Critical => $"{CriticalTag} {CriticalText}{m}{Reset}",
LogLevel.Trace => $"{traceTag} {TraceText}{m}{Reset}",
LogLevel.Debug => $"{debugTag} {DebugText}{m}{Reset}",
LogLevel.Information => $"{informationTag} {InformationText}{m}{Reset}",
LogLevel.Warning => $"{warningTag} {WarningText}{m}{Reset}",
LogLevel.Error => $"{errorTag} {ErrorText}{m}{Reset}",
LogLevel.Critical => $"{criticalTag} {CriticalText}{m}{Reset}",
_ => null,
});
}
Expand Down

0 comments on commit 573f89c

Please sign in to comment.