Example #1
0
        private void CreateDefaultNLogListener(NLogOptions verbOptions, ISessionManager sessionManager)
        {
            var name = $"Using nlog listener on {(verbOptions.IsUdp ? "Udp" : "Tcp")} port {verbOptions.Port}";
            var info = NLogViewerProvider.ProviderRegistrationInformation.Info;

            Log.Debug(name);

            var providerSettings = new NetworkSettings
            {
                Protocol =
                    verbOptions.IsUdp
                        ? NetworkProtocol.Udp
                        : NetworkProtocol.Tcp,
                Port = verbOptions.Port,
                Name = name,
                Info = info,
            };
            var providers = Enumerable.Repeat(
                new PendingProviderRecord {
                Info = info, Settings = providerSettings
            },
                1);

            sessionManager.LoadProviders(providers);
        }
Example #2
0
        /// <summary>
        /// 对AddNLog的一个简单封装,注册NLog,并设置配置文件,默认dllconfigs/Overt.Core.Logging.nlog.dll.config
        /// </summary>
        /// <param name="loggingBuilder"></param>
        /// <param name="configFile"></param>
        public static ILoggingBuilder AddNLogLogging(this ILoggingBuilder loggingBuilder, Action <NLogOptions> config = null)
        {
            ConfigureExtensions.AddNLog(loggingBuilder);

            var options = new NLogOptions();

            config?.Invoke(options);

            if (string.IsNullOrEmpty(options.ConfigFile))
            {
                options.ConfigFile = Path.Combine(AppContext.BaseDirectory, "dllconfigs/Overt.Core.Logging.nlog.dll.config");
            }

            if (!File.Exists(options.ConfigFile))
            {
                throw new FileNotFoundException(options.ConfigFile);
            }

            if (options.ThrowExceptions != null)
            {
                NLog.LogManager.ThrowExceptions = options.ThrowExceptions.Value;
            }
            if (options.ThrowConfigExceptions != null)
            {
                NLog.LogManager.ThrowConfigExceptions = options.ThrowConfigExceptions.Value;
            }

            if (options.CustomVarialbes.Count > 0)
            {
                foreach (var item in options.CustomVarialbes)
                {
                    NLog.LayoutRenderers.LayoutRenderer.Register(item.Key, le => LoggingUtility.GetCachedValue(item.Key, item.Value));
                }
            }

            NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(options.ConfigFile, false);

            return(loggingBuilder);
        }