/// <inheritdoc /> public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { // First we take care about output to console. if (consoleLogger.IsEnabled(logLevel)) { consoleLogger.Log(logLevel, eventId, state, exception, (s, e) => { return(prefix + formatter(s, e)); }); } // The rest of the method cares about logging via NLog to files. NLog.LogLevel nLogLevel = logLevel.ToNLogLevel(); if (!IsEnabled(nLogLevel)) { return; } if (formatter == null) { throw new ArgumentNullException(nameof(formatter)); } string message = prefix + formatter(state, exception); LogEventInfo eventInfo = LogEventInfo.Create(nLogLevel, logger.Name, message); eventInfo.Exception = exception; logger.Log(wrapperType, eventInfo); }
public Task <JobResult> RunAsync(CancellationToken cancellationToken = default(CancellationToken)) { Interlocked.Increment(ref _iterationCount); if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Sample1Job Run #{IterationCount} Thread={ManagedThreadId}", _iterationCount, Thread.CurrentThread.ManagedThreadId); } return(Task.FromResult(JobResult.Success)); }
/// <summary> /// Log a message at critical level /// </summary> /// <param name="logger">extended logger</param> /// <param name="level">log level</param> /// <param name="exception">exception</param> /// <param name="message">message</param> /// <param name="line">compiler injected line number</param> /// <param name="member">compiler injected class member</param> /// <param name="file">compiler injected file</param> private static void Log([NotNull] ILogger2 logger, LogLevel level, Exception?exception, Func <string> message, [CallerLineNumber] int?line = null, [CallerMemberName] string?member = null, [CallerFilePath] string?file = null) { if (!logger.IsEnabled(level)) { return; } var lld = new LogLocationDetail(line, member, file); logger.Log(level, default, lld, exception, (s, e) => message());
public static void Log(this ILogger logger, LogMessage message) { LogLevel level = message.Severity.ToLogLevel(); if (!logger.IsEnabled(level)) { return; } using (logger.BeginScope(new Dictionary <string, object>() { { "Source", $"DiscordNet: {message.Source}" } })) { logger.Log(level, message.Exception, message.Message); } }
private static void HexLoggingFormatter(Microsoft.Extensions.Logging.ILogger logger, string method, ReadOnlySpan <byte> buffer) { if (!logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) { return; } var builder = new StringBuilder($"{method}[{buffer.Length}] "); // Write the hex foreach (var b in buffer) { builder.Append(b.ToString("X2")); builder.Append(" "); } logger.LogTrace(builder.ToString()); }
/// <inheritdoc /> public bool IsEnabled(LogLevel level) { return(_logger.IsEnabled(level.ToMicrosoftLogLevel())); }
public bool IsEnabled(NHibernateLogLevel logLevel) { return(_logger.IsEnabled(MapToCoreLogLevel(logLevel))); }
public bool IsDebugEnabled() => _logger.IsEnabled(LogLevel.Debug);
bool Microsoft.Extensions.Logging.ILogger.IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel);
public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { return(_logger.IsEnabled(logLevel)); }
public bool IsEnabled(LogLevel logLevel) { return(_baseLogger.IsEnabled(logLevel)); }
public bool IsEnabled(LogLevel logLevel) { return(adaptee.IsEnabled(logLevel)); }
public bool IsEnabled(DnsClient.Internal.LogLevel logLevel) { return(_logger.IsEnabled((Microsoft.Extensions.Logging.LogLevel)logLevel)); }
public bool IsEnabled(LogLevel logLevel) { return(_logger.IsEnabled(GetLogLevel(logLevel))); }
public bool IsEnabled(NHibernateLogLevel logLevel) { return(_msLogger.IsEnabled(MapLevels[logLevel])); }