コード例 #1
0
        /// <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);
        }
コード例 #2
0
 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));
 }
コード例 #3
0
        /// <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());
コード例 #4
0
ファイル: Logging.cs プロジェクト: darocha/WSBC-DiscordBot
        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);
            }
        }
コード例 #5
0
        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());
        }
コード例 #6
0
ファイル: MicrosoftLogger.cs プロジェクト: AppCoreNet/Logging
 /// <inheritdoc />
 public bool IsEnabled(LogLevel level)
 {
     return(_logger.IsEnabled(level.ToMicrosoftLogLevel()));
 }
コード例 #7
0
 public bool IsEnabled(NHibernateLogLevel logLevel)
 {
     return(_logger.IsEnabled(MapToCoreLogLevel(logLevel)));
 }
コード例 #8
0
 public bool IsDebugEnabled() => _logger.IsEnabled(LogLevel.Debug);
コード例 #9
0
 bool Microsoft.Extensions.Logging.ILogger.IsEnabled(LogLevel logLevel) =>
 _logger.IsEnabled(logLevel);
コード例 #10
0
 public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel)
 {
     return(_logger.IsEnabled(logLevel));
 }
コード例 #11
0
 public bool IsEnabled(LogLevel logLevel)
 {
     return(_baseLogger.IsEnabled(logLevel));
 }
コード例 #12
0
 public bool IsEnabled(LogLevel logLevel)
 {
     return(adaptee.IsEnabled(logLevel));
 }
コード例 #13
0
ファイル: Program.cs プロジェクト: zhouzu/DnsClient.NET
 public bool IsEnabled(DnsClient.Internal.LogLevel logLevel)
 {
     return(_logger.IsEnabled((Microsoft.Extensions.Logging.LogLevel)logLevel));
 }
コード例 #14
0
ファイル: Logger.cs プロジェクト: EsWork/Es.Logging
 public bool IsEnabled(LogLevel logLevel)
 {
     return(_logger.IsEnabled(GetLogLevel(logLevel)));
 }
コード例 #15
0
 public bool IsEnabled(NHibernateLogLevel logLevel)
 {
     return(_msLogger.IsEnabled(MapLevels[logLevel]));
 }