zoukankan      html  css  js  c++  java
  • NLog WriteToTargets method

     public void Debug(Exception exception, [Localizable(false)] string message)
            {
                if (IsDebugEnabled)
                {
                    WriteToTargets(LogLevel.Debug, exception, message, null);
                }
            }

    https://github.com/NLog/NLog/blob/dev/src/NLog/Logger.cs#L599

    private void WriteToTargets(LogLevel level, Exception ex, [Localizable(false)] string message, object[] args)

     private void WriteToTargets(LogLevel level, Exception ex, [Localizable(false)] string message, object[] args)
            {
                var targetsForLevel = GetTargetsForLevel(level);
                if (targetsForLevel != null)
                {
                    var logEvent = LogEventInfo.Create(level, Name, ex, Factory.DefaultCultureInfo, message, args);
                    WriteToTargets(logEvent, targetsForLevel);
                }
            }
      private void WriteToTargets([NotNull] LogEventInfo logEvent, [NotNull] TargetWithFilterChain targetsForLevel)
            {
                LoggerImpl.Write(DefaultLoggerType, targetsForLevel, PrepareLogEventInfo(logEvent), Factory);
            }
      [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", Justification = "Using 'NLog' in message.")]
            internal static void Write([NotNull] Type loggerType, [NotNull] TargetWithFilterChain targetsForLevel, LogEventInfo logEvent, LogFactory logFactory)
            {
                logEvent.SetMessageFormatter(logFactory.ActiveMessageFormatter, targetsForLevel.NextInChain == null ? logFactory.SingleTargetMessageFormatter : null);
    
    #if CaptureCallSiteInfo
                StackTraceUsage stu = targetsForLevel.GetStackTraceUsage();
                if (stu != StackTraceUsage.None)
                {
                    bool attemptCallSiteOptimization = targetsForLevel.TryCallSiteClassNameOptimization(stu, logEvent);
                    if (attemptCallSiteOptimization && targetsForLevel.TryLookupCallSiteClassName(logEvent, out string callSiteClassName))
                    {
                        logEvent.CallSiteInformation.CallerClassName = callSiteClassName;
                    }
                    else if (attemptCallSiteOptimization || targetsForLevel.MustCaptureStackTrace(stu, logEvent))
                    {
                        CaptureCallSiteInfo(logFactory, loggerType, logEvent, stu);
    
                        if (attemptCallSiteOptimization)
                        {
                            targetsForLevel.TryRememberCallSiteClassName(logEvent);
                        }
                    }
                }
    #endif
    
                AsyncContinuation exceptionHandler = (ex) => { };
                if (logFactory.ThrowExceptions)
                {
                    int originalThreadId = AsyncHelpers.GetManagedThreadId();
                    exceptionHandler = ex =>
                    {
                        if (ex != null && AsyncHelpers.GetManagedThreadId() == originalThreadId)
                        {
                            throw new NLogRuntimeException("Exception occurred in NLog", ex);
                        }
                    };
                }
    
                IList<Filter> prevFilterChain = null;
                FilterResult prevFilterResult = FilterResult.Neutral;
                for (var t = targetsForLevel; t != null; t = t.NextInChain)
                {
                    FilterResult result = ReferenceEquals(prevFilterChain, t.FilterChain) ?
                        prevFilterResult : GetFilterResult(t.FilterChain, logEvent, t.DefaultResult);
                    if (!WriteToTargetWithFilterChain(t.Target, result, logEvent, exceptionHandler))
                    {
                        break;
                    }
    
                    prevFilterResult = result;  // Cache the result, and reuse it for the next target, if it comes from the same logging-rule
                    prevFilterChain = t.FilterChain;
                }
            }
  • 相关阅读:
    ng-深度学习-课程笔记-1: 介绍深度学习(Week1)
    java发送http请求和多线程
    Spring Cloud Eureka注册中心(快速搭建)
    Spring boot集成Swagger2,并配置多个扫描路径,添加swagger-ui-layer
    springboot在idea的RunDashboard如何显示出来
    Oracle 中select XX_id_seq.nextval from dual 什么意思呢?
    mysql类似to_char()to_date()函数mysql日期和字符相互转换方法date_f
    MySQL的Limit详解
    HikariCP 个人实例
    NBA-2018骑士季后赛
  • 原文地址:https://www.cnblogs.com/chucklu/p/13253598.html
Copyright © 2011-2022 走看看