/// <inheritdoc/> public void Log(object entry) { LogEntry logEntry = StdJsonLogging.NormalizeToLogEntry(entry, SerializerSource); string dotNetTypePrefix = logEntry.DotNetType == null ? string.Empty : $"{logEntry.DotNetType}: "; _writeAction($"{logEntry.Instant.InZone(_localZone):hh:mm:ss.f}: {dotNetTypePrefix}{logEntry.Message}"); }
/// <inheritdoc/> public void Log(object entry) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } string serializedEntry = StdJsonLogging.NormalizeToString(entry, SerializerSource); _innerLogger.Log(serializedEntry); }
/// <inheritdoc/> public object Build(object entry) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } object currentEntry = _innerBuilder?.Build(entry) ?? entry; LogEntry logEntry = StdJsonLogging.NormalizeToLogEntry(currentEntry, SerializerSource); return(_buildDelegate(logEntry)); }
/// <inheritdoc/> public void Log(object entry) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } LogEntry logEntry = StdJsonLogging.NormalizeToLogEntry(entry, SerializerSource); logEntry.DotNetType = TypeName; _innerLogger.Log(logEntry); }
/// <inheritdoc/> public void Log(object entry) { LogEntry logEntry = StdJsonLogging.NormalizeToLogEntry(entry, SerializerSource); // TODO: Implement nested scopes. logEntry.SetExtensionData( ExtensionDataKey, new StdLogScope { Id = _scopeId }); _inner.Log(logEntry); }
/// <inheritdoc/> public void Log(object entry) { LogEntry logEntry = StdJsonLogging.NormalizeToLogEntry(entry, SerializerSource); string dotNetTypePrefix = logEntry.DotNetType == null ? string.Empty : $"{logEntry.DotNetType}: "; ConsoleColor colorBackup = Console.ForegroundColor; if (logEntry.Severity > _maxSeverity) { return; } try { switch (logEntry.Severity) { case LogSeverity.Critical: Console.ForegroundColor = ConsoleColor.Red; break; case LogSeverity.Error: Console.ForegroundColor = ConsoleColor.DarkRed; break; case LogSeverity.Warning: Console.ForegroundColor = ConsoleColor.DarkYellow; break; case LogSeverity.Info: Console.ForegroundColor = ConsoleColor.White; break; case LogSeverity.Trace: Console.ForegroundColor = ConsoleColor.Gray; break; case LogSeverity.Debug: Console.ForegroundColor = ConsoleColor.DarkGray; break; default: Console.ForegroundColor = ConsoleColor.DarkGray; break; } string scopePrefix = string.Empty; if (logEntry.ExtensionData != null && logEntry.ExtensionData.TryGetValue(ScopedLogger.ExtensionDataKey, out object scopeInfo)) { if (scopeInfo is JObject jobj) { if (jobj.TryGetValue("id", out JToken value)) { scopePrefix = value.ToString(); } } else if (scopeInfo is StdLogScope stdLogScope) { scopePrefix = stdLogScope.Id.ToString(); } if (scopePrefix != string.Empty) { scopePrefix += "=> "; } } Console.WriteLine( $"{logEntry.Instant.InZone(_localZone):hh:mm:ss.f}: {dotNetTypePrefix}{scopePrefix}{logEntry.Message}"); if (logEntry.Exception != null) { var baseIntent = " |"; Console.Write(baseIntent); Console.WriteLine( "------------------------------------- Exception ---------------------------------------"); string intent = string.Empty; ExceptionDto curException = logEntry.Exception; do { Console.Write(baseIntent); Console.Write(intent); if (intent != string.Empty) { Console.Write("<--"); } string name = curException.TypeFullName?.Split('.')?.Last() ?? "NullName"; Console.WriteLine($"{name}: {curException.Message}"); curException = curException.InnerException; intent += " "; }while (curException != null); Console.Write(baseIntent); Console.WriteLine( "---------------------------------------------------------------------------------------"); } } finally { Console.ForegroundColor = colorBackup; } }