• log4net初探


    /// <summary>
            /// Static constructor that initializes logging by reading 
            /// settings from the application configuration file.
            /// </summary>
            /// <remarks>
            /// <para>
            /// The <c>log4net.Internal.Debug</c> application setting
            /// controls internal debugging. This setting should be set
            /// to <c>true</c> to enable debugging.
            /// </para>
            /// <para>
            /// The <c>log4net.Internal.Quiet</c> application setting
            /// suppresses all internal logging including error messages. 
            /// This setting should be set to <c>true</c> to enable message
            /// suppression.
            /// </para>
            /// </remarks>
            static LogLog()
            {
    #if !NETCF
                try
                {
                    InternalDebugging = OptionConverter.ToBoolean(SystemInfo.GetAppSetting("log4net.Internal.Debug"), false);
                    QuietMode = OptionConverter.ToBoolean(SystemInfo.GetAppSetting("log4net.Internal.Quiet"), false);
                    EmitInternalMessages = OptionConverter.ToBoolean(SystemInfo.GetAppSetting("log4net.Internal.Emit"), true);
                }
                catch(Exception ex)
                {
                    // If an exception is thrown here then it looks like the config file does not
                    // parse correctly.
                    //
                    // We will leave debug OFF and print an Error message
                    Error(typeof(LogLog), "Exception while reading ConfigurationSettings. Check your .config file is well formed XML.", ex);
                }
    #endif
            }
        #region Public Static Properties
    
            /// <summary>
            /// Gets or sets a value indicating whether log4net internal logging
            /// is enabled or disabled.
            /// </summary>
            /// <value>
            /// <c>true</c> if log4net internal logging is enabled, otherwise 
            /// <c>false</c>.
            /// </value>
            /// <remarks>
            /// <para>
            /// When set to <c>true</c>, internal debug level logging will be 
            /// displayed.
            /// </para>
            /// <para>
            /// This value can be set by setting the application setting 
            /// <c>log4net.Internal.Debug</c> in the application configuration
            /// file.
            /// </para>
            /// <para>
            /// The default value is <c>false</c>, i.e. debugging is
            /// disabled.
            /// </para>
            /// </remarks>
            /// <example>
            /// <para>
            /// The following example enables internal debugging using the 
            /// application configuration file :
            /// </para>
            /// <code lang="XML" escaped="true">
            /// <configuration>
            ///        <appSettings>
            ///            <add key="log4net.Internal.Debug" value="true" />
            ///        </appSettings>
            /// </configuration>
            /// </code>
            /// </example>
            public static bool InternalDebugging
            {
                get { return s_debugEnabled; }
                set { s_debugEnabled = value; }
            }
    
            /// <summary>
            /// Gets or sets a value indicating whether log4net should generate no output
            /// from internal logging, not even for errors. 
            /// </summary>
            /// <value>
            /// <c>true</c> if log4net should generate no output at all from internal 
            /// logging, otherwise <c>false</c>.
            /// </value>
            /// <remarks>
            /// <para>
            /// When set to <c>true</c> will cause internal logging at all levels to be 
            /// suppressed. This means that no warning or error reports will be logged. 
            /// This option overrides the <see cref="InternalDebugging"/> setting and 
            /// disables all debug also.
            /// </para>
            /// <para>This value can be set by setting the application setting
            /// <c>log4net.Internal.Quiet</c> in the application configuration file.
            /// </para>
            /// <para>
            /// The default value is <c>false</c>, i.e. internal logging is not
            /// disabled.
            /// </para>
            /// </remarks>
            /// <example>
            /// The following example disables internal logging using the 
            /// application configuration file :
            /// <code lang="XML" escaped="true">
            /// <configuration>
            ///        <appSettings>
            ///            <add key="log4net.Internal.Quiet" value="true" />
            ///        </appSettings>
            /// </configuration>
            /// </code>
            /// </example>
            public static bool QuietMode
            {
                get { return s_quietMode; }
                set { s_quietMode = value; }
            }
    
            /// <summary>
            /// 
            /// </summary>
            public static bool EmitInternalMessages
            {
                get { return s_emitInternalMessages; }
                set { s_emitInternalMessages = value; }
            }
    
            #endregion Public Static Properties
     /// <summary>
            /// Raises the LogReceived event when an internal messages is received.
            /// </summary>
            /// <param name="source"></param>
            /// <param name="prefix"></param>
            /// <param name="message"></param>
            /// <param name="exception"></param>
            public static void OnLogReceived(Type source, string prefix, string message, Exception exception)
            {
                if (LogReceived != null)
                {
                    LogReceived(null, new LogReceivedEventArgs(new LogLog(source, prefix, message, exception)));
                }
            }
    
            /// <summary>
            /// Test if LogLog.Debug is enabled for output.
            /// </summary>
            /// <value>
            /// <c>true</c> if Debug is enabled
            /// </value>
            /// <remarks>
            /// <para>
            /// Test if LogLog.Debug is enabled for output.
            /// </para>
            /// </remarks>
            public static bool IsDebugEnabled
            {
                get { return s_debugEnabled && !s_quietMode; }
            }
    
            /// <summary>
            /// Writes log4net internal debug messages to the 
            /// standard output stream.
            /// </summary>
            /// <param name="source"></param>
            /// <param name="message">The message to log.</param>
            /// <remarks>
            /// <para>
            ///    All internal debug messages are prepended with 
            ///    the string "log4net: ".
            /// </para>
            /// </remarks>
            public static void Debug(Type source, string message) 
            {
                if (IsDebugEnabled) 
                {
                    if (EmitInternalMessages)
                    {
                        EmitOutLine(PREFIX + message);
                    }
    
                    OnLogReceived(source, PREFIX, message, null);
                }
            }
    
            /// <summary>
            /// Writes log4net internal debug messages to the 
            /// standard output stream.
            /// </summary>
            /// <param name="source">The Type that generated this message.</param>
            /// <param name="message">The message to log.</param>
            /// <param name="exception">An exception to log.</param>
            /// <remarks>
            /// <para>
            ///    All internal debug messages are prepended with 
            ///    the string "log4net: ".
            /// </para>
            /// </remarks>
            public static void Debug(Type source, string message, Exception exception) 
            {
                if (IsDebugEnabled) 
                {
                    if (EmitInternalMessages)
                    {
                        EmitOutLine(PREFIX + message);
                        if (exception != null)
                        {
                            EmitOutLine(exception.ToString());
                        }
                    }
    
                    OnLogReceived(source, PREFIX, message, exception);
                }
            }
      
            /// <summary>
            /// Test if LogLog.Warn is enabled for output.
            /// </summary>
            /// <value>
            /// <c>true</c> if Warn is enabled
            /// </value>
            /// <remarks>
            /// <para>
            /// Test if LogLog.Warn is enabled for output.
            /// </para>
            /// </remarks>
            public static bool IsWarnEnabled
            {
                get { return !s_quietMode; }
            }
    
            /// <summary>
            /// Writes log4net internal warning messages to the 
            /// standard error stream.
            /// </summary>
            /// <param name="source">The Type that generated this message.</param>
            /// <param name="message">The message to log.</param>
            /// <remarks>
            /// <para>
            ///    All internal warning messages are prepended with 
            ///    the string "log4net:WARN ".
            /// </para>
            /// </remarks>
            public static void Warn(Type source, string message) 
            {
                if (IsWarnEnabled)
                {
                    if (EmitInternalMessages)
                    {
                        EmitErrorLine(WARN_PREFIX + message);
                    }
    
                    OnLogReceived(source, WARN_PREFIX, message, null);
                }
            }  
  • 相关阅读:
    句柄
    类,方法,抽象方法,接口
    Enum类型
    String 为什么是不可变的
    大数据怎么排序
    oracle创建表空间 导入数据库
    eclipse常见小问题
    eclipse创建项目
    存储过程
    在VMware通过挂载系统光盘搭建本地yum仓库
  • 原文地址:https://www.cnblogs.com/ck0074451665/p/6764752.html
Copyright © 2020-2023  润新知