private static void CreateTraceLabLoggingRule()
 {
     // Enable all messages from TraceLab
     var allErrorsRule = new NLog.Config.LoggingRule();
     allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Info);
     allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Trace);
     allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Debug);
     allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Warn);
     allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Error);
     allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Fatal);
     allErrorsRule.LoggerNamePattern = "TraceLab*";
     NLog.LogManager.Configuration.LoggingRules.Add(allErrorsRule);
 }
示例#2
0
        /// <summary>
        /// Регистрируем правила Nlog для строки состояния
        /// </summary>
        /// <param name="methodName">Имя статического метода который будет вызываться при появлении сообщения.</param>
        /// <param name="className">Имя класа в котором находится метод.</param>
        public static void MakeNewStatusTargetForNlog(string methodName, string className)
        {
            NLog.Config.LoggingConfiguration config = LogManager.Configuration;
            if (config.FindTargetByName("status") != null)
            {
                return;
            }
            NLog.Targets.MethodCallTarget targetLog = new NLog.Targets.MethodCallTarget();
            targetLog.Name       = "status";
            targetLog.MethodName = methodName;
            targetLog.ClassName  = className;
            targetLog.Parameters.Add(new NLog.Targets.MethodCallParameter("${message}"));
            config.AddTarget("status", targetLog);
            NLog.Config.LoggingRule rule = new NLog.Config.LoggingRule("*", targetLog);
            rule.EnableLoggingForLevel(LogLevel.Info);
            config.LoggingRules.Add(rule);

            LogManager.Configuration = config;
        }
示例#3
0
        /// <summary>
        /// Creates the logging rules for each log level for given logger name
        /// </summary>
        /// <param name="loggerName">Name of the logger.</param>
        /// <param name="logLevels">The log levels.</param>
        private static void CreateLoggingRules(string loggerName, IEnumerable <TraceLab.Core.Settings.LogLevelItem> logLevels)
        {
            NLog.Config.LoggingRule loggingRule = null;

            foreach (TraceLab.Core.Settings.LogLevelItem logLevelItem in logLevels)
            {
                if (logLevelItem.IsEnabled)
                {
                    if (loggingRule == null)
                    {
                        loggingRule = CreateRule(loggerName, logLevelItem.Level);
                    }

                    loggingRule.EnableLoggingForLevel(logLevelItem.Level);
                }
            }

            NLog.LogManager.ReconfigExistingLoggers();
        }
示例#4
0
        private static void CreateTraceLabLoggingRule()
        {
            // Enable all messages from TraceLab
            var allErrorsRule = new NLog.Config.LoggingRule();

            allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Info);
            allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Trace);
            allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Debug);
            allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Warn);
            allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Error);
            allErrorsRule.EnableLoggingForLevel(NLog.LogLevel.Fatal);
            allErrorsRule.LoggerNamePattern = "TraceLab*";
            NLog.LogManager.Configuration.LoggingRules.Add(allErrorsRule);
        }
示例#5
0
        private static void ConfigRule(NLog.Config.LoggingRule rule, int minLevel)
        {
            //Disable all loglevel rules
            for (int i = 0; i < 6; i++)
            {
                rule.DisableLoggingForLevel(LogLevel.FromOrdinal(i));
            }

            //Enable present loglevel rules up to maxLevel
            if (minLevel > 0)
            {
                for (int i = 0; i <= minLevel; i++)
                {
                    var logLevel = LogLevel.FromOrdinal(6 - i);
                    if (logLevel != LogLevel.Off)
                    {
                        rule.EnableLoggingForLevel(logLevel);
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// Регистрируем правила Nlog для строки состояния
        /// </summary>
        /// <param name="methodName">Имя статического метода который будет вызываться при появлении сообщения.</param>
        /// <param name="className">Имя класа в котором находится метод.</param>
        public static void MakeNewStatusTargetForNlog(string methodName, string className)
        {
            NLog.Config.LoggingConfiguration config = LogManager.Configuration;
            if (config.FindTargetByName ("status") != null)
                return;
            NLog.Targets.MethodCallTarget targetLog = new NLog.Targets.MethodCallTarget ();
            targetLog.Name = "status";
            targetLog.MethodName = methodName;
            targetLog.ClassName = className;
            targetLog.Parameters.Add (new NLog.Targets.MethodCallParameter ("${message}"));
            config.AddTarget ("status", targetLog);
            NLog.Config.LoggingRule rule = new NLog.Config.LoggingRule ("*", targetLog);
            rule.EnableLoggingForLevel (LogLevel.Info);
            config.LoggingRules.Add (rule);

            LogManager.Configuration = config;
        }