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


C# LoggingLevel类代码示例

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


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

示例1: LogException

 public void LogException(MethodBase methodBase, Exception err, LoggingLevel exceptionLevel)
 {
     ILog logger = LogManager.GetLogger(methodBase.DeclaringType);
     if (ShouldLog(logger, exceptionLevel, methodBase)) {
         exceptionLogger.LogException(err, false, methodBase.DeclaringType);
     }
 }
开发者ID:robiee4u,项目名称:Sharp-Architecture-Contrib,代码行数:7,代码来源:MethodLogger.cs

示例2: Create

        /// <summary>
        /// Parses the XML of the configuration section.
        /// </summary>
        /// <param name="parent">The configuration settings in a corresponding parent configuration section.</param>
        /// <param name="configContext">An HttpConfigurationContext when Create is called from the ASP.NET configuration system. Otherwise, this parameter is reserved and is a null reference.</param>
        /// <param name="section">The XmlNode that contains the configuration information from the configuration file. Provides direct access to the XML contents of the configuration section.</param>
        /// <returns>A configuration object.</returns>
        public object Create(object parent, object configContext, XmlNode section)
        {
            XmlElement loggingElement = (XmlElement) section;
            if (loggingElement.HasAttribute("LoggingLevel"))
            {
                loggingLevel = (LoggingLevel) Enum.Parse(typeof(LoggingLevel), loggingElement.GetAttribute("LoggingLevel"), true);
            }
            else
            {
                loggingLevel = LoggingLevel.Off;
            }

            if (loggingElement.HasChildNodes)
            {
                foreach (XmlElement element in loggingElement.SelectNodes("logger"))
                {
                    string typeName = element.GetAttribute("type");

                    // Use reflection to create an instance of the configured Logger instance
                    Type type = Type.GetType(typeName);
                    LoggerBase logger = (LoggerBase) type.Assembly.CreateInstance(type.FullName);
                    logger.Configure(element);
                    loggers.Add(logger);
                }
            }

            return this;
        }
开发者ID:SolidSnake74,项目名称:SharpCore,代码行数:35,代码来源:LoggingSectionHandler.cs

示例3: LogItem

 /// <summary>
 /// Initializes a new LogItem class
 /// </summary>
 /// <param name="message">Message to log</param>
 /// <param name="exception">Exception to log</param>
 /// <param name="level">Message level</param>
 public LogItem(string message, Exception exception = null, LoggingLevel level = LoggingLevel.Info)
 {
     Message = message;
     Exception = exception;
     Created = DateTime.UtcNow;
     Level = level;
 }
开发者ID:Grinderofl,项目名称:Logger,代码行数:13,代码来源:LogItem.cs

示例4: LogEntry

        public override void LogEntry(string source, string message, LoggingLevel loggingLevel)
        {
            if (EventLog.Exists(logName))
            {
                StringWriter writer = new StringWriter();
                writer.WriteLine("Source: " + source);
                writer.WriteLine("Message: " + message);
                message = writer.ToString();

                switch (loggingLevel)
                {
                    case LoggingLevel.Error:
                        EventLog.WriteEntry(logName, message, EventLogEntryType.Error);
                        break;
                    case LoggingLevel.Warning:
                        EventLog.WriteEntry(logName, message, EventLogEntryType.Warning);
                        break;
                    case LoggingLevel.Information:
                    case LoggingLevel.Verbose:
                        EventLog.WriteEntry(logName, message, EventLogEntryType.Information);
                        break;
                    default:
                        break;
                }
            }
            else
            {
                StringWriter writer = new StringWriter();
                writer.WriteLine("Entries cannot be written to the " + logName + " log because it does not exist.");
                writer.WriteLine("Source: " + source);
                writer.WriteLine("Message: " + message);

                throw new InvalidOperationException(writer.ToString());
            }
        }
开发者ID:SolidSnake74,项目名称:SharpCore,代码行数:35,代码来源:EventLogLogger.cs

示例5: CommonServiceException

 /// <summary>
 /// Initializes a new instance of the 
 /// <see cref="T:WebApplications.Utilities.Logging.LoggingException" /> class.
 /// </summary>
 /// <param name="level">The log level.</param>
 /// <param name="resource">The resource expression, e.g. ()=&gt; Resources.Log_Message.</param>
 /// <param name="parameters">The parameters.</param>
 internal CommonServiceException(
     LoggingLevel level,
     [CanBeNull] Expression<Func<string>> resource,
     [CanBeNull] params object[] parameters)
     : base(level, resource, parameters)
 {
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:14,代码来源:CommonServiceException.cs

示例6: WriteLog

            public static void WriteLog(string messageFormat, LoggingLevel loggingLevel = LoggingLevel.Default, params object[] args) {
                //WriteLog(String.Format(message, args), loggingLevel);
#if DEBUG
                lock (lockFlag) {
#endif
                    {
                        string message = messageFormat;
                        bool isNotMessageFormatted = true;

                        try {
                            message = string.Format(messageFormat, args);
                            isNotMessageFormatted = false;
                        }
                        catch { }

                        WriteConsole(message);

                        if (IsLoggingToFileEnabled) {
                            if (message.Length < 20 * 1024) {
                                LogToFile(message);
                            }
                        }
                    }
#if DEBUG
                }
#endif
            }
开发者ID:vhnatyk,项目名称:WebMarco.2.0,代码行数:27,代码来源:Utilities.cs

示例7: DatabaseSchemaException

 /// <summary>
 /// Initializes a new instance of the <see cref="LoggingException" /> class.
 /// </summary>
 /// <param name="level">The severity of the exception being logged.</param>
 /// <param name="resource">The resource expression, e.g. ()=&gt; Resources.Log_Message.</param>
 /// <param name="parameters">The parameters.</param>
 public DatabaseSchemaException(
     LoggingLevel level,
     [CanBeNull] Expression<Func<string>> resource,
     [CanBeNull] params object[] parameters)
     : base(level, resource, parameters)
 {
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:13,代码来源:DatabaseSchemaException.cs

示例8: Log

 public static void Log(LoggingLevel level, Exception exception)
 {
     if (exception != null)
     {
         Log(level, exception.ToString());
     }
 }
开发者ID:WPT-KL,项目名称:Kongliang,代码行数:7,代码来源:Logger.cs

示例9: Log

        protected override void Log(LoggingLevel level, object sender, object message, object verbose, Exception t)
        {
            if (!(IsVerboseEnabled))
                verbose = "";

            WriteLine(level, message.ToString() + "; " + t.ToString() + "; " + verbose, sender); // do not localize
        }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:7,代码来源:WebTraceLogger.cs

示例10: Log

 public void Log(Exception exception, LoggingLevel loggingLevel, [CallerMemberName] string memberName = "", [CallerFilePath] string classFilePath = "", [CallerLineNumber]int line = 0)
 {
     if (exception != null)
     {
         Log(exception.Message, loggingLevel, memberName, classFilePath, line);
     }
 }
开发者ID:maliroteh,项目名称:SalesforceMobileSDK-Windows,代码行数:7,代码来源:Logger.cs

示例11: Log

 /// <summary>
 /// Log a message
 /// </summary>
 /// <param name="level"></param>
 /// <param name="function"></param>
 /// <param name="message"></param>
 /// <param name="ex"></param>
 public static void Log(LoggingLevel level, string function, string message, Exception ex)
 {
     if (level >= minLevel)
     {
         // log message to file, email, pager
     }
 }
开发者ID:jediskywalker,项目名称:RTDeals,代码行数:14,代码来源:Logging.cs

示例12: Logger

 public Logger(string path, LoggingLevel level, params TextWriter[] otherOutputs)
 {
     _path = path;
     _level = level;
     _otherOutputs = otherOutputs;
     _messageBuffer = new List<string>();
 }
开发者ID:brascoball,项目名称:sensus,代码行数:7,代码来源:Logger.cs

示例13: LogEntry

        public void LogEntry(MethodBase methodBase, object[] argumentValues, LoggingLevel entryLevel)
        {
            var logger = LogManager.GetLogger(methodBase.DeclaringType);
            if (this.ShouldLog(logger, entryLevel, methodBase))
            {
                var logMessage = new StringBuilder();
                logMessage.Append(string.Format("{0}(", methodBase.Name));

                var parameterInfos = methodBase.GetParameters();
                if (argumentValues != null && parameterInfos != null)
                {
                    for (var i = 0; i < argumentValues.Length; i++)
                    {
                        if (i > 0)
                        {
                            logMessage.Append(" ");
                        }

                        logMessage.Append(string.Format("{0}:[{1}]", parameterInfos[i].Name, argumentValues[i]));
                    }
                }

                logMessage.Append(")");
                logger.Log(entryLevel, logMessage.ToString());
            }
        }
开发者ID:barser,项目名称:Sharp-Architecture-Contrib,代码行数:26,代码来源:MethodLogger.cs

示例14: LogMessage

        private static void LogMessage(object sender, LoggingLevel loggingLevel, string message, params object[] args)
        {
            try
            {
                string loggerName = "Main";
                if (sender != null)
                {
                    loggerName = sender.GetType().Name;
                }

                message = string.Format(message, args);

                Logger logger = LogManager.GetLogger(loggerName);
                switch (loggingLevel)
                {
                    case LoggingLevel.Error: logger.Error(message); break;
                    case LoggingLevel.Warning: logger.Warn(message); break;
                    case LoggingLevel.Info: logger.Info(message); break;
                    case LoggingLevel.Critical: logger.Fatal(message); break;
                    default: logger.Debug(message); break;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("NLog exception: {0}, {1}", ex.Message, ex.StackTrace));
            }
        }
开发者ID:SresgaminG,项目名称:ArmamutE,代码行数:27,代码来源:LogHelper.cs

示例15: ShouldLog

        private bool ShouldLog(ILog logger, LoggingLevel loggingLevel, MethodBase methodBase)
        {
            if (methodBase != null && methodBase.Name != null) {
                return logger.IsEnabledFor(loggingLevel);
            }

            return false;
        }
开发者ID:robiee4u,项目名称:Sharp-Architecture-Contrib,代码行数:8,代码来源:MethodLogger.cs


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