当前位置: 首页>>代码示例>>C#>>正文


C# LoggingRule.EnableLoggingForLevel方法代码示例

本文整理汇总了C#中NLog.Config.LoggingRule.EnableLoggingForLevel方法的典型用法代码示例。如果您正苦于以下问题:C# LoggingRule.EnableLoggingForLevel方法的具体用法?C# LoggingRule.EnableLoggingForLevel怎么用?C# LoggingRule.EnableLoggingForLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NLog.Config.LoggingRule的用法示例。


在下文中一共展示了LoggingRule.EnableLoggingForLevel方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EnableDebugConsoleOutput

        public static void EnableDebugConsoleOutput()
        {
            if (IsDebugConsoleOutputEnabled) {
                return;
            }

            LoggingConfiguration config = LogManager.Configuration;
            ConsoleTarget consoleTarget = new ConsoleTarget() { Name = "consoleDebugOutput" };
            LoggingRule consoleRule = new LoggingRule("*", consoleTarget);

            consoleRule.EnableLoggingForLevel(LogLevel.Trace);
            consoleRule.EnableLoggingForLevel(LogLevel.Debug);
            config.AddTarget(consoleTarget);
            config.LoggingRules.Add(consoleRule);
            IsDebugConsoleOutputEnabled = true;
        }
开发者ID:CTCal,项目名称:GO-Bot,代码行数:16,代码来源:NLogConfig.cs

示例2: ConfigureLogging

        private static void ConfigureLogging(bool enableVerboseLogging)
        {
            var config = new LoggingConfiguration();

            var consoleTarget = new ColoredConsoleTarget();
            config.AddTarget("console", consoleTarget);

            consoleTarget.Layout = "> ${message}";

            var rule1 = new LoggingRule("*", LogLevel.Info, consoleTarget);

            if (enableVerboseLogging)
            {
                rule1.EnableLoggingForLevel(LogLevel.Trace);
                rule1.EnableLoggingForLevel(LogLevel.Debug);
            }

            config.LoggingRules.Add(rule1);

            LogManager.Configuration = config;
        }
开发者ID:skfd,项目名称:PluginAssemblyLoader,代码行数:21,代码来源:Program.cs

示例3: ChangeRuleMinLevel

 private static void ChangeRuleMinLevel(LoggingRule rule, LogLevel minLevel)
 {
     /*
      * Based on how the LoggingLevel initializes its logging levels when given a minLevel,
      * but because LogLevel.MinLevel and LogLevel.MaxLevel are not publically accessible,
      * their current values are hardcoded. TODO: This is fragile!
      */
     for (var i = LogLevel.Trace.Ordinal; i < minLevel.Ordinal; i++)
     {
         rule.DisableLoggingForLevel(LogLevel.FromOrdinal(i));
     }
     for (var i = minLevel.Ordinal; i <= LogLevel.Fatal.Ordinal; i++)
     {
         rule.EnableLoggingForLevel(LogLevel.FromOrdinal(i));
     }
     LogManager.ReconfigExistingLoggers();
 }
开发者ID:xor-freenet,项目名称:wintray,代码行数:17,代码来源:PreferencesWindow.cs

示例4: ParseLoggerElement

        /// <summary>
        /// Parse {Logger} xml element
        /// </summary>
        /// <param name="loggerElement"></param>
        /// <param name="rulesCollection">Rules are added to this parameter.</param>
        private void ParseLoggerElement(NLogXmlElement loggerElement, IList<LoggingRule> rulesCollection)
        {
            loggerElement.AssertName("logger");

            var namePattern = loggerElement.GetOptionalAttribute("name", "*");
            var enabled = loggerElement.GetOptionalBooleanAttribute("enabled", true);
            if (!enabled)
            {
                InternalLogger.Debug("The logger named '{0}' are disabled");
                return;
            }

            var rule = new LoggingRule();
            string appendTo = loggerElement.GetOptionalAttribute("appendTo", null);
            if (appendTo == null)
            {
                appendTo = loggerElement.GetOptionalAttribute("writeTo", null);
            }

            rule.LoggerNamePattern = namePattern;
            if (appendTo != null)
            {
                foreach (string t in appendTo.Split(','))
                {
                    string targetName = t.Trim();
                    Target target = FindTargetByName(targetName);

                    if (target != null)
                    {
                        rule.Targets.Add(target);
                    }
                    else
                    {
                        throw new NLogConfigurationException("Target " + targetName + " not found.");
                    }
                }
            }

            rule.Final = loggerElement.GetOptionalBooleanAttribute("final", false);

            string levelString;

            if (loggerElement.AttributeValues.TryGetValue("level", out levelString))
            {
                LogLevel level = LogLevel.FromString(levelString);
                rule.EnableLoggingForLevel(level);
            }
            else if (loggerElement.AttributeValues.TryGetValue("levels", out levelString))
            {
                levelString = CleanSpaces(levelString);

                string[] tokens = levelString.Split(',');
                foreach (string s in tokens)
                {
                    if (!string.IsNullOrEmpty(s))
                    {
                        LogLevel level = LogLevel.FromString(s);
                        rule.EnableLoggingForLevel(level);
                    }
                }
            }
            else
            {
                int minLevel = 0;
                int maxLevel = LogLevel.MaxLevel.Ordinal;
                string minLevelString;
                string maxLevelString;

                if (loggerElement.AttributeValues.TryGetValue("minLevel", out minLevelString))
                {
                    minLevel = LogLevel.FromString(minLevelString).Ordinal;
                }

                if (loggerElement.AttributeValues.TryGetValue("maxLevel", out maxLevelString))
                {
                    maxLevel = LogLevel.FromString(maxLevelString).Ordinal;
                }

                for (int i = minLevel; i <= maxLevel; ++i)
                {
                    rule.EnableLoggingForLevel(LogLevel.FromOrdinal(i));
                }
            }

            foreach (var child in loggerElement.Children)
            {
                switch (child.LocalName.ToUpper(CultureInfo.InvariantCulture))
                {
                    case "FILTERS":
                        this.ParseFilters(rule, child);
                        break;

                    case "LOGGER":
                        this.ParseLoggerElement(child, rule.ChildRules);
                        break;
//.........这里部分代码省略.........
开发者ID:shadowca,项目名称:NLog,代码行数:101,代码来源:XmlLoggingConfiguration.cs

示例5: ParseLoggerElement

        private void ParseLoggerElement(XmlReader reader, ICollection<LoggingRule> rulesCollection)
        {
            LoggingRule rule = new LoggingRule();
            string namePattern = this.GetCaseInsensitiveAttribute(reader, "name", "*");
            string appendTo = this.GetCaseInsensitiveAttribute(reader, "appendTo", null);
            if (appendTo == null)
            {
                appendTo = this.GetCaseInsensitiveAttribute(reader, "writeTo", null);
            }

            rule.LoggerNamePattern = namePattern;
            if (appendTo != null)
            {
                foreach (string t in appendTo.Split(','))
                {
                    string targetName = t.Trim();
                    Target target = FindTargetByName(targetName);

                    if (target != null)
                    {
                        rule.Targets.Add(target);
                    }
                    else
                    {
                        throw new NLogConfigurationException("Target " + targetName + " not found.");
                    }
                }
            }

            rule.Final = false;

            if (this.GetCaseInsensitiveAttribute(reader, "final", "false") == "true")
            {
                rule.Final = true;
            }

            string levelString;

            if (this.TryGetCaseInsensitiveAttribute(reader, "level", out levelString))
            {
                LogLevel level = LogLevel.FromString(levelString);
                rule.EnableLoggingForLevel(level);
            }
            else if (this.TryGetCaseInsensitiveAttribute(reader, "levels", out levelString))
            {
                levelString = this.CleanWhitespace(levelString);

                string[] tokens = levelString.Split(',');
                foreach (string s in tokens)
                {
                    if (!string.IsNullOrEmpty(s))
                    {
                        LogLevel level = LogLevel.FromString(s);
                        rule.EnableLoggingForLevel(level);
                    }
                }
            }
            else
            {
                int minLevel = 0;
                int maxLevel = LogLevel.MaxLevel.Ordinal;
                string minLevelString;
                string maxLevelString;

                if (this.TryGetCaseInsensitiveAttribute(reader, "minLevel", out minLevelString))
                {
                    minLevel = LogLevel.FromString(minLevelString).Ordinal;
                }

                if (this.TryGetCaseInsensitiveAttribute(reader, "maxLevel", out maxLevelString))
                {
                    maxLevel = LogLevel.FromString(maxLevelString).Ordinal;
                }

                for (int i = minLevel; i <= maxLevel; ++i)
                {
                    rule.EnableLoggingForLevel(LogLevel.FromOrdinal(i));
                }
            }

            if (!reader.IsEmptyElement)
            {
                while (this.MoveToNextElement(reader))
                {
                    switch (reader.LocalName.ToLower(CultureInfo.InvariantCulture))
                    {
                        case "filters":
                            this.ParseFilters(rule, reader);
                            break;

                        case "logger":
                            this.ParseLoggerElement(reader, rule.ChildRules);
                            break;

                        default:
                            reader.Skip();
                            break;
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:igalse,项目名称:NLog,代码行数:101,代码来源:XmlLoggingConfiguration.cs

示例6: SetLogLevelForRule

        private void SetLogLevelForRule(LoggingRule rule, LogLevel activeLogLevel)
        {
            // Reset all log levels to off
            for (int i = MinLogLevel; i <= MaxLogLevel; i++)
            {
                rule.DisableLoggingForLevel(LogLevel.FromOrdinal(i));
            }

            // Enable the active log level and all levels numerically higher
            for (int i = activeLogLevel.GetHashCode(); i <= MaxLogLevel; i++)
            {
                rule.EnableLoggingForLevel(LogLevel.FromOrdinal(i));
            }

            InternalLogger.Debug("*** Setting active log level for " + _logger.Name + " to " + activeLogLevel.Name);
        }
开发者ID:BogamSushil,项目名称:OnlineGrocery,代码行数:16,代码来源:NLogLogWriter.cs

示例7: EnableWarningLogging

        public static void EnableWarningLogging()
        {
            if (IsWarningLoggingEnabled) {
                return;
            }

            LoggingConfiguration config = LogManager.Configuration;
            FileTarget warningTarget = new FileTarget() {
                Name = "fileWarnings",
                Layout = "${longdate} | ${level:uppercase=true} | ${logger} | ${message}",
                FileName = BaseLogDirectory + @"\Warning\warning.log",
                ArchiveFileName = BaseLogDirectory + @"\MobiBot\Warning\warning.{###}.txt",
                ArchiveEvery = FileArchivePeriod.Day,
                ArchiveNumbering = ArchiveNumberingMode.Rolling,
                MaxArchiveFiles = 30,
                NetworkWrites = true,
                KeepFileOpen = true
            };
            LoggingRule warningRule = new LoggingRule("*", warningTarget);

            warningRule.EnableLoggingForLevel(LogLevel.Warn);
            config.AddTarget(warningTarget);
            config.LoggingRules.Add(warningRule);
            IsWarningLoggingEnabled = true;
        }
开发者ID:CTCal,项目名称:GO-Bot,代码行数:25,代码来源:NLogConfig.cs

示例8: ApplyLogLevel

        private void ApplyLogLevel(LoggingRule rule, IList<LogLevel> levels)
        {
            foreach (var level in rule.Levels)
                rule.DisableLoggingForLevel(level);

            foreach (var level in levels)
                rule.EnableLoggingForLevel(level);
        }
开发者ID:juankakode,项目名称:Drone,代码行数:8,代码来源:DroneApp.cs

示例9: MvcApplication_BeginRequest

        void MvcApplication_BeginRequest(object sender, EventArgs e)
        {
            try
            {
                if (HttpContext.Current.Request.QueryString["vm"] != null && Convert.ToInt32(HttpContext.Current.Request.QueryString["vm"]) == 10)
                {
                    MemoryTarget _logTarget = null;
                    _loggerName = Guid.NewGuid().ToString().Replace("-", string.Empty);
                    HttpContext.Current.Items.Add("LoggerName", _loggerName);
                    _logTarget = new MemoryTarget();
                    _logTarget.Name = _loggerName.ToString();

                    LoggingRule rule = new LoggingRule(_loggerName, _logTarget);
                    rule.EnableLoggingForLevel(LogLevel.Debug);
                    rule.EnableLoggingForLevel(LogLevel.Trace);
                    rule.EnableLoggingForLevel(LogLevel.Info);
                    rule.EnableLoggingForLevel(LogLevel.Warn);
                    rule.EnableLoggingForLevel(LogLevel.Error);
                    rule.EnableLoggingForLevel(LogLevel.Fatal);

                    LogManager.Configuration.LoggingRules.Add(rule);

                    LogManager.Configuration.Reload();
                }
            }
            catch (Exception ex)
            {
                LogEventInfo info = new LogEventInfo(LogLevel.Error, ECMSSettings.DEFAULT_LOGGER, ex.ToString());
                ECMSLogger.Instance.Log(info);
            }
        }
开发者ID:ramkumar013,项目名称:ECMS,代码行数:31,代码来源:Global.asax.cs


注:本文中的NLog.Config.LoggingRule.EnableLoggingForLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。