nlog配置文件的自动查找

https://github.com/NLog/NLog/blob/dev/src/NLog/Config/LoggingConfigurationFileLoader.cs#L222

复制代码
 /// <summary>
        /// Get default file paths (including filename) for possible NLog config files. 
        /// </summary>
        public IEnumerable<string> GetDefaultCandidateConfigFilePaths(string filename = null)
        {
            if (filename == null)
            {
                // Scan for process specific nlog-files
                foreach (var filePath in GetAppSpecificNLogLocations())
                    yield return filePath;
            }

            // NLog.config from application directory
            string nlogConfigFile = filename ?? "NLog.config";
            string baseDirectory = PathHelpers.TrimDirectorySeparators(_appEnvironment.AppDomainBaseDirectory);
            if (!string.IsNullOrEmpty(baseDirectory))
                yield return Path.Combine(baseDirectory, nlogConfigFile);

            string nLogConfigFileLowerCase = nlogConfigFile.ToLower();
            bool platformFileSystemCaseInsensitive = nlogConfigFile == nLogConfigFileLowerCase || PlatformDetector.IsWin32;
            if (!platformFileSystemCaseInsensitive && !string.IsNullOrEmpty(baseDirectory))
                yield return Path.Combine(baseDirectory, nLogConfigFileLowerCase);

#if !NETSTANDARD1_3
            string entryAssemblyLocation = PathHelpers.TrimDirectorySeparators(_appEnvironment.EntryAssemblyLocation);
#else
            string entryAssemblyLocation = string.Empty;
#endif
            if (!string.IsNullOrEmpty(entryAssemblyLocation) && !string.Equals(entryAssemblyLocation, baseDirectory, StringComparison.OrdinalIgnoreCase))
            {
                yield return Path.Combine(entryAssemblyLocation, nlogConfigFile);
                if (!platformFileSystemCaseInsensitive)
                    yield return Path.Combine(entryAssemblyLocation, nLogConfigFileLowerCase);
            }

            if (string.IsNullOrEmpty(baseDirectory))
            {
                yield return nlogConfigFile;
                if (!platformFileSystemCaseInsensitive)
                    yield return nLogConfigFileLowerCase;
            }

            foreach (var filePath in GetPrivateBinPathNLogLocations(baseDirectory, nlogConfigFile, platformFileSystemCaseInsensitive ? nLogConfigFileLowerCase : string.Empty))
                yield return filePath;

            string nlogAssemblyLocation = filename != null ? null : LookupNLogAssemblyLocation();
            if (nlogAssemblyLocation != null)
                yield return nlogAssemblyLocation + ".nlog";
        }
复制代码

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(285)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2019-07-14 HearthBuddy的狂野和休闲模式来回切换
2019-07-14 查看HearthBuddy.exe文件是x86还是x64版本
2019-07-14 hearthbuddy中的Class276
2019-07-14 Cannot use unsafe construct in safe context
2019-07-14 HearthBuddy炉石兄弟 Method 'CollectionDeckBoxVisual.IsValid' not found.
2017-07-14 RedGate
2016-07-14 TeeChart中 Line的Clear方法
点击右上角即可分享
微信分享提示