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


C# NLog.LogLevel类代码示例

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


LogLevel类属于NLog命名空间,在下文中一共展示了LogLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigureViaCode

        public static void ConfigureViaCode(LogLevel consoleLogLevel, LogLevel fileLogLevel)
        {
            // Step 1. Create configuration object
            var config = new LoggingConfiguration();

            // Step 2. Create targets and add them to the configuration
            var consoleTarget = new ConsoleTarget();
            config.AddTarget("console", consoleTarget);

            var fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);

            // Step 3. Set target properties
            consoleTarget.Layout = @"${message} ${onexception:EXCEPTION\:${exception:format=tostring}}";

            fileTarget.Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss.fff} [${level:uppercase=true}] ${message}  ${onexception:EXCEPTION\:${exception:format=tostring}}";
            fileTarget.FileName = "C:\\temp\\logs\\SpiderOpenQuant.${date:format=yyyy-MM-dd hh}.log";
            fileTarget.ConcurrentWrites = false;
            fileTarget.KeepFileOpen = true;
            fileTarget.OpenFileCacheTimeout = 60;

            // Step 4. Define rules
            var rule1 = new LoggingRule("*", consoleLogLevel, consoleTarget);
            config.LoggingRules.Add(rule1);

            var rule2 = new LoggingRule("*", fileLogLevel, fileTarget);
            config.LoggingRules.Add(rule2);

            // Step 5. Activate the configuration
            LogManager.Configuration = config;
        }
开发者ID:aggarwalmanuj,项目名称:open-quant,代码行数:31,代码来源:LogConfigurator.cs

示例2: Compile

        public void Compile(DroneEnv env, LogLevel logLevel)
        {
            if (this.IsRecompileNeeded(env.Config))
            {
                var result = this.CompileCore(env);

                try
                {
                    if (result.IsSuccess)
                    {
                        this.CreateCache(env.Config);
                        this.log.Log(logLevel, "compiled ({0})", HumanTime.Format(result.TimeElapsed));
                    }
                    else
                    {
                        throw DroneCompilerException.Get(result);
                    }
                }
                finally
                {
                    this.LogResult(result);
                }
            }
            else
            {
                this.log.Log(logLevel, "compiliation skipped, all files up to date");
            }
        }
开发者ID:juankakode,项目名称:Drone,代码行数:28,代码来源:DroneCompiler.cs

示例3: DicomParserLogger

 public DicomParserLogger(Logger log, LogLevel level)
 {
     _log = log;
     _level = level;
     _depth = 0;
     _pad = String.Empty;
 }
开发者ID:anqin888,项目名称:fo-dicom,代码行数:7,代码来源:DicomParserLogger.cs

示例4: Configure

        public static void Configure(LogLevel logLevel = null)
        {
            logLevel = logLevel ?? LogLevel.Info;

            // log layout format
            var layout = "${date:format=hh\\:mm\\:ss tt} ${pad:padding=6:inner=${level:uppercase=true}} ${message} ${exception:separator=\r\n:format=message,type,method,stackTrace:maxInnerExceptionLevel=10:innerExceptionSeparator=\r\n:innerFormat=message,type,method,stackTrace}";

            // initialize logging configuration
            var config = LogManager.Configuration ?? new LoggingConfiguration();

            // create console target
            if (!Debugger.IsAttached)
            {
                var consoleTarget = new ColoredConsoleTarget();
                consoleTarget.Layout = layout;
                config.AddTarget("console", consoleTarget);
                config.LoggingRules.Add(new LoggingRule("*", logLevel, consoleTarget));
            }
            else
            {
                var consoleTarget = new DebuggerTarget();
                consoleTarget.Layout = layout;
                config.AddTarget("console", consoleTarget);
                config.LoggingRules.Add(new LoggingRule("*", logLevel, consoleTarget));
            }

            // activate configuration and bind
            LogManager.Configuration = config;
        }
开发者ID:pmlyon,项目名称:BitSharp,代码行数:29,代码来源:ConsoleLoggingModule.cs

示例5: Write

 public void Write(CommonLogger logType, LogLevel level, string message)
 {
     Logger logger = LoggerRepository.BuildLogger(logType);
     StringBuilder info = new StringBuilder();
     if (HttpContext.Current != null)
     {
         var urlReferrer = HttpContext.Current.Request.UrlReferrer;
         if (urlReferrer != null)
         {
             info.AppendLine("前一个请求地址:" + urlReferrer.ToString());
         }
         var behavior = HttpContext.Current.Request.Cookies["user"];
         if (behavior != null)
         {
             info.AppendLine("据用户跟踪,用户为:" + behavior);
         }
         info.AppendLine("MethodType:" + HttpContext.Current.Request.HttpMethod);
         info.AppendLine("ClientIP:" + HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString());
         info.AppendLine("Browser:" + HttpContext.Current.Request.Browser.Type);
         if (HttpContext.Current.User.Identity.IsAuthenticated)
         {
             info.AppendLine("LoginUser:" + HttpContext.Current.User.Identity.Name);
         }
         info.AppendLine("请求地址:" + HttpContext.Current.Request.RawUrl);
     }
     DoWrite(logger, level, info.ToString() + message);
 }
开发者ID:zhangfaguo,项目名称:ShowTime,代码行数:27,代码来源:LogHelper.cs

示例6: testLogLevel

    void testLogLevel(Action<string> logMethod, LogLevel logLvl, bool shouldLog)
    {
        var didLog = false;
        LogLevel eventLogLevel = LogLevel.Off;
        string eventMessage = null;
        Logger eventLogger = null;
        _logger.OnLog += (logger, logLevel, msg) => {
            didLog = true;
            eventLogger = logger;
            eventLogLevel = logLevel;
            eventMessage = msg;
        };

        logMethod(Message);

        didLog.should_be(shouldLog);

        if (shouldLog) {
            eventLogger.should_be_same(_logger);
            eventMessage.should_be(Message);
            eventLogLevel.should_be(logLvl);
        } else {
            eventMessage.should_be_null();
            eventLogLevel.should_be(LogLevel.Off);
            eventLogger.should_be_null();
        }
    }
开发者ID:sschmid,项目名称:NLog,代码行数:27,代码来源:describe_Logger.cs

示例7: Log

 public void Log(string s, LogLevel level)
 {
     var box = level == LogLevel.Debug || level == LogLevel.Info || level == LogLevel.Trace ? infoBox : logBox;
     while (box.Items.Count > 8)
         box.Items.RemoveAt(0);
     box.Items.Add(s);
 }
开发者ID:PakosChivaldori,项目名称:KMine,代码行数:7,代码来源:MainForm.cs

示例8: Log

 public void Log(LogLevel level, object value)
 {
     if (this.IsEnabled(level))
     {
         this.WriteToTargets(level, "{0}", new object[] { value });
     }
 }
开发者ID:semirs,项目名称:CellAO,代码行数:7,代码来源:Logger-V1Compat.cs

示例9: SetChainsawLevel

 private static void SetChainsawLevel(LogLevel minimumLevel)
 {
     SetTargetLevel(
         ChainsawTargetName,
         minimumLevel,
         targetName => new ChainsawTarget { Name = targetName, Address = "udp://127.0.0.1:7071" });
 }
开发者ID:croquet-australia,项目名称:croquet-australia-logging,代码行数:7,代码来源:LoggerConfiguration.cs

示例10: LogMessageModel

 public LogMessageModel(string message, LogLevel level, DateTime date)
 {
     this.Date = date;
     this.message = message;
     this.level = level;
     IsVisible = true;
 }
开发者ID:dEMonaRE,项目名称:HearthstoneTracker,代码行数:7,代码来源:LogMessageModel.cs

示例11: SendPayload

        private void SendPayload(LogLevel level, string message, Exception exception)
        {
            if (exception == null)
            {
                return;
            }
            string exceptionType;
            var stackBuilder = new StringBuilder();

            do
            {
                exceptionType = exception.GetType().Name;
                stackBuilder.AppendLine(exception.Message);
                stackBuilder.AppendLine(exception.StackTrace);
                exception = exception.InnerException;
            } while (exception != null);

            manager.SendLoggingPayload(new LoggingPayload
            {
                StackTrace = stackBuilder.ToString(),
                Message = message,
                LogLevel = level.Name,
                ExceptionType = exceptionType
            });
        }
开发者ID:jorgechen,项目名称:CoolFish,代码行数:25,代码来源:RemoteTarget.cs

示例12: LogNode

        public LogNode(XmlNode xmlNode,  ScriptableScraper context)
            : base(xmlNode, context)
        {
            try { logLevel = LogLevel.FromString(xmlNode.Attributes["LogLevel"].Value); }
            catch (Exception e) {
                if (e.GetType() == typeof(ThreadAbortException))
                    throw e;

                try { logLevel = LogLevel.FromString(xmlNode.Attributes["log_level"].Value); }
                catch (Exception e2) {
                    if (e2.GetType() == typeof(ThreadAbortException))
                        throw e2;

                    logLevel = LogLevel.Debug;
                }
            }

            try { message = xmlNode.Attributes["Message"].Value; }
            catch (Exception e) {
                if (e.GetType() == typeof(ThreadAbortException))
                    throw e;

                try { message = xmlNode.Attributes["message"].Value; }
                catch (Exception e2) {
                    if (e2.GetType() == typeof(ThreadAbortException))
                        throw e2;

                    logger.Error("Missing MESSAGE attribute on: " + xmlNode.OuterXml);
                    loadSuccess = false;
                    return;
                }
            }

            loadSuccess = true;
        }
开发者ID:damienhaynes,项目名称:moving-pictures,代码行数:35,代码来源:LogNode.cs

示例13: SetNLogTarget

 public static void SetNLogTarget(Target target, LogLevel minLevel = null)
 {
     if (target != null)
     {
         SimpleConfigurator.ConfigureForTargetLogging(target, minLevel ?? LogLevel.Info);
     }
 }
开发者ID:svn2github,项目名称:ecm7migrator,代码行数:7,代码来源:MigratorLogManager.cs

示例14: LogProgressMessage

        private static void LogProgressMessage(Logger logger, LogLevel level, string message)
        {
            var logEvent = new LogEventInfo(level, logger.Name, message);
            logEvent.Properties.Add("Status", "");

            logger.Log(logEvent);
        }
开发者ID:BubbaFatAss,项目名称:NzbDrone,代码行数:7,代码来源:LoggerExtensions.cs

示例15: Write

            public void Write(LogLevel level, LogEvent logEvent)
            {
                LogBuilder fluent;
                switch (level)
                {
                    case LogLevel.Trace:
                        fluent = _logger.Trace();
                        break;
                    case LogLevel.Info:
                        fluent = _logger.Info();
                        break;
                    case LogLevel.Warning:
                        fluent = _logger.Warn();
                        break;
                    case LogLevel.Error:
                        fluent = _logger.Error();
                        break;
                    case LogLevel.Critical:
                        fluent = _logger.Fatal();
                        break;
                    default:
                        throw new ApplicationException("Invalid log level");
                }

                if (!string.IsNullOrWhiteSpace(logEvent.Message))
                    fluent.Message(logEvent.Message);
                if (logEvent.Exception != null)
                    fluent.Exception(logEvent.Exception);
                foreach (var parameter in logEvent.Parameters)
                {
                    fluent.Property(parameter.Key, parameter.Value);
                }
                fluent.Write();
            }
开发者ID:WalnutBrain,项目名称:Core,代码行数:34,代码来源:NlogLoggerProvider.cs


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