in src/Google.Cloud.Functions.Hosting/Logging/SimpleConsoleLogger.cs [28:60]
internal SimpleConsoleLogger(string category, IExternalScopeProvider? scopeProvider, TextWriter console)
: base(category, scopeProvider) => _console = console;
protected override void LogImpl<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, string formattedMessage)
{
// Note: these are deliberately the same values used by ASP.NET Core's console logger.
string briefLevel = 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))
};
StringBuilder scopeBuilder = new StringBuilder();
ScopeProvider.ForEachScope(AppendScope, scopeBuilder);
_console.WriteLine(Invariant($"{DateTime.UtcNow:yyyy-MM-dd'T'HH:mm:ss.fff'Z'} [{Category}] [{briefLevel}] {formattedMessage}"));
// Note: it's not ideal to break out of the "one line per log entry" approach for either scopes or exceptions,
// but there's no particularly nice way of getting all the relevant information otherwise.
if (scopeBuilder.Length != 0)
{
_console.WriteLine($"Scopes: [{scopeBuilder}]");
}
if (exception is object)
{
_console.WriteLine(ToInvariantString(exception));
}
}