• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# log4net类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Log4NetProxy

        public Log4NetProxy(log4net.ILog logger)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");

            _logger = logger;
        }
开发者ID:gavinramm,项目名称:Afterglow,代码行数:7,代码来源:Log4netProxy.cs


示例2: Append

 protected override void Append(log4net.Core.LoggingEvent loggingEvent)
 {
     if (this._ErrorLog != null)
     {
         Error error;
         if (loggingEvent.ExceptionObject != null)
         {
             error = new Error(loggingEvent.ExceptionObject);
         }
         else
         {
             error = new Error();
         }
         error.Time = DateTime.Now;
         if (loggingEvent.MessageObject != null)
         {
             error.Message = loggingEvent.MessageObject.ToString();
         }
         error.Detail = base.RenderLoggingEvent(loggingEvent);
         error.HostName = this._HostName;
         error.User = loggingEvent.Identity;
         error.Type = "log4net - " + loggingEvent.Level; // maybe allow the type to be customized?
         this._ErrorLog.Log(error);
     }
 }
开发者ID:jmachale,项目名称:log4net---ELMAH-Appender,代码行数:25,代码来源:ELMAHAppender.cs


示例3: AddProperties

        private void AddProperties(object logSource, Exception exception, log4net.Core.LoggingEvent loggingEvent)
        {
            loggingEvent.Properties["UserName"] = GetUserName();
            try
            {
                ContextProperties contextProperties = _contextService.GetContextProperties();
                if (contextProperties != null)
                {
                    try
                    {
                        loggingEvent.Properties["UserAgent"] = contextProperties.UserAgent;
                        loggingEvent.Properties["RemoteHost"] = contextProperties.RemoteHost;
                        loggingEvent.Properties["Path"] = contextProperties.Path;
                        loggingEvent.Properties["Query"] = contextProperties.Query;
                        loggingEvent.Properties["RefererUrl"] = contextProperties.Referrer;
                        loggingEvent.Properties["RequestId"] = contextProperties.RequestId;
                        loggingEvent.Properties["SessionId"] = contextProperties.SessionId;
                    }
                    catch (Exception)
                    {
                    }
                }

                loggingEvent.Properties["ExceptionType"] = exception == null ? "" : exception.GetType().ToString();
                loggingEvent.Properties["ExceptionMessage"] = exception == null ? "" : exception.Message;
                loggingEvent.Properties["ExceptionStackTrace"] = exception == null ? "" : exception.StackTrace;
                loggingEvent.Properties["LogSource"] = logSource.GetType().ToString();
            }
            catch (Exception ex)
            {
                var type = typeof(Log4NetLoggingService);
                var logger = LogManager.GetLogger(type);
                logger.Logger.Log(type, log4net.Core.Level.Fatal, "Exception when extracting properties: " + ex.Message, ex);
            }
        }
开发者ID:LalithaSharma,项目名称:gail,代码行数:35,代码来源:Log4NetLoggingService.cs


示例4: Append

 protected override void Append(log4net.Core.LoggingEvent loggingEvent)
 {
     if (_textBox == null) return;
     var text = string.Format("{3}{0}{1}{2}",loggingEvent.RenderedMessage, Environment.NewLine, _textBox.Text,loggingEvent.LoggerName);
     if (text.Length > TextLength) text = text.Substring(0, TextLength);
     _textBox.Text = text;
 }
开发者ID:jansaris,项目名称:KinectV2,代码行数:7,代码来源:TextBoxAppender.cs


示例5: Append

        protected override void Append(log4net.Core.LoggingEvent loggingEvent)
        {
            // get the new log4net ILog instance for the logger name we are using
            object logger = getLoggerMethod.Invoke(null, new object[] {loggingEvent.LoggerName});

            //Action<object, Exception> logMethod;
            MethodInfo logMethod;
            if (loggingEvent.Level == log4net.Core.Level.Warn) {
                logMethod = warnMethod;
            } else if (loggingEvent.Level == log4net.Core.Level.Debug) {
                logMethod = debugMethod;
            } else if (loggingEvent.Level == log4net.Core.Level.Info) {
                logMethod = infoMethod;
            } else if (loggingEvent.Level == log4net.Core.Level.Fatal) {
                logMethod = fatalMethod;
            } else if (loggingEvent.Level == log4net.Core.Level.Error) {
                logMethod = errorMethod;
            } else {
                log4net.Util.LogLog.Error("Unknown log level " + (loggingEvent.Level == null ? "[null]" : loggingEvent.Level.Name));
                logMethod = null;
            }

            if (logMethod != null) {
                logMethod.Invoke(logger, new object[] { loggingEvent.RenderedMessage, loggingEvent.ExceptionObject });
            }
        }
开发者ID:SpotlightUK,项目名称:Log4NetRedirector,代码行数:26,代码来源:Log4NetRedirectorAppender.cs


示例6: Append

        protected override void Append(log4net.Core.LoggingEvent loggingEvent)
        {
            var hashMessage = new StringBuilder()
                .Append(loggingEvent.Level.Value.ToString())
                .Append(loggingEvent.LoggerName)
                .Append("_")
                .Append(loggingEvent.RenderedMessage)
                .ToString();

            var smallHash = hashMessage.Substring(0, 32);
            smallHash = Hash.GetHash(smallHash, Hash.HashType.SHA256);
            var bigHash = Hash.GetHash(hashMessage, Hash.HashType.SHA256);

            var connection = new SqlConnection();
            connection.ConnectionString = ConnectionString;
            connection.Open();
            var cmd = new SqlCommand("AddHashLog", connection);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add("smallhash", System.Data.SqlDbType.Char, 64).Value = smallHash;
            cmd.Parameters.Add("bighash", System.Data.SqlDbType.Char, 64).Value = bigHash;
            cmd.Parameters.Add("logger", System.Data.SqlDbType.VarChar).Value = loggingEvent.LoggerName;
            cmd.Parameters.Add("level", System.Data.SqlDbType.TinyInt).Value = (byte)(loggingEvent.Level.Value + 1);
            cmd.Parameters.Add("date", System.Data.SqlDbType.DateTime2, 7).Value = loggingEvent.TimeStamp;
            cmd.Parameters.Add("message", System.Data.SqlDbType.VarChar).Value = loggingEvent.RenderedMessage;
            cmd.ExecuteNonQuery();
            connection.Close();
        }
开发者ID:yolpsoftware,项目名称:HashLogAppender,代码行数:27,代码来源:HashLogAppender.cs


示例7: Append

 /// <summary>
 /// Addes a log entry to the Execution Control's LogEntries property
 /// http://www.dotmaniac.net/display-log4net-entries-in-wpf-datagrid-in-real-time/
 /// </summary>
 /// <remarks>
 /// Appender does not log debug messages
 /// </remarks>
 protected override void Append(log4net.Core.LoggingEvent loggingEvent)
 {
     DispatcherHelper.CheckBeginInvokeOnUI(() =>
     {
         LogEvents.Add(loggingEvent);
     });
 }
开发者ID:stefanocastriotta,项目名称:MDbGui.Net,代码行数:14,代码来源:WpfAppender.cs


示例8: Append

 protected override void Append(log4net.Core.LoggingEvent loggingEvent)
 {
     using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
     {
         Layout.Format(sw, loggingEvent);
         //The textbox may not be ready at this point, so cache the appended
         //entries into a temp buffer until a textbox is ready. When it is
         //write the contents of the buffer first before writing the most
         //recent event
         if (_TextBox != null && !_TextBox.IsDisposed)
         {
             string content = sw.ToString();
             string level = loggingEvent.Level.Name;
             if (_TextBox.InvokeRequired)
             {
                 _TextBox.BeginInvoke(new WriteContentHandler(this.WriteContent), content, level);
             }
             else
             {
                 WriteContent(content, level);
             }
         }
         else if (_buffer != null)
         {
             _buffer.Append(sw.ToString());
         }
     }
 }
开发者ID:stophun,项目名称:fdotoolbox,代码行数:28,代码来源:TextBoxAppender.cs


示例9: LogLevelSeverityToSysLogLevelSeverity

        public static int LogLevelSeverityToSysLogLevelSeverity(log4net.Core.Level level)
        {
            if (level == log4net.Core.Level.Alert) return (int)LocalSyslogAppender.SyslogSeverity.Alert;

            if (level == log4net.Core.Level.Critical || level == log4net.Core.Level.Fatal) return (int)LocalSyslogAppender.SyslogSeverity.Critical;

            if (level == log4net.Core.Level.Debug) return (int)LocalSyslogAppender.SyslogSeverity.Debug;

            if (level == log4net.Core.Level.Emergency) return (int)LocalSyslogAppender.SyslogSeverity.Emergency;

            if (level == log4net.Core.Level.Error) return (int)LocalSyslogAppender.SyslogSeverity.Error;

            if (level == log4net.Core.Level.Fine || level == log4net.Core.Level.Finer
                || level == log4net.Core.Level.Finest || level == log4net.Core.Level.Info
                || level == log4net.Core.Level.Off) return (int)LocalSyslogAppender.SyslogSeverity.Informational;

            if (level == log4net.Core.Level.Notice || level == log4net.Core.Level.Verbose
                || level == log4net.Core.Level.Trace) return (int)LocalSyslogAppender.SyslogSeverity.Notice;

            if (level == log4net.Core.Level.Severe) return (int)LocalSyslogAppender.SyslogSeverity.Emergency;

            if (level == log4net.Core.Level.Warn) return (int)LocalSyslogAppender.SyslogSeverity.Warning;

            return (int)LocalSyslogAppender.SyslogSeverity.Debug;
        }
开发者ID:Skyscanner,项目名称:gelf4net,代码行数:25,代码来源:SeverityLevelConverter.cs


示例10: NewTask

        public override VendScreen.Common.TaskManager.ITask NewTask(log4net.ILog log)
        {
            if (!this.Task.CommandsEnabled()) return null;
            var task = new VSSyncExportTask() {Config = this, Logger = log};

            return task;
        }
开发者ID:siarheimilkevich,项目名称:VSSync,代码行数:7,代码来源:VMSConfig.designer.cs


示例11: GoogleMapsEngineAPI

        /*
         * Constructor for Google Maps API utilities
         */
        public GoogleMapsEngineAPI(ref log4net.ILog log)
        {
            // establish the Google APIs project key
            this.GOOGLE_API_KEY = Properties.Settings.Default.gme_api_key;

            // establish the Google Maps Engine API settings
            this.GME_API_PROTOCOL = Properties.Settings.Default.gme_api_protocol;
            this.GME_API_DOMAIN = Properties.Settings.Default.gme_api_domain;
            this.GME_API_SERVICE = Properties.Settings.Default.gme_api_service;
            this.GME_API_VERSION = Properties.Settings.Default.gme_api_version;

            // set the log
            this.log = log;

            // retrieve a reference to the extension
            log.Debug("Retrieiving a reference to the extension object.");
            ext = GoogleMapsEngineToolsExtensionForArcGIS.GetExtension();

            // create a Google Maps Engine Session Id for this set of sessions
            GoogleMapsEngineAPISessionId = Guid.NewGuid();

            // if debug, create a debug folder to keep track of information
            if (log.IsDebugEnabled)
            {
                // create a temporary folder
                debugDirectory = System.IO.Directory.CreateDirectory(
                    ext.getLocalWorkspaceDirectory()
                    + "\\GME_API_TMP_"
                    + GoogleMapsEngineAPISessionId.ToString().Replace("-",""));
            }
        }
开发者ID:romarknmsu,项目名称:mapsengine-arcgis-connector,代码行数:34,代码来源:GoogleMapsEngineAPI.cs


示例12: Convert

        private static Severity Convert(log4net.Core.Level level)
        {
            if (level == log4net.Core.Level.Debug)
            {
                return Severity.Debug;
            }
            else if (level == log4net.Core.Level.Info)
            {
                return Severity.Information;
            }
            else if (level == log4net.Core.Level.Warn)
            {
                return Severity.Warning;
            }
            else if (level == log4net.Core.Level.Error)
            {
                return Severity.Error;
            }
            else if (level == log4net.Core.Level.Trace)
            {
                return Severity.Trace;
            }

            return Severity.Information;
        }
开发者ID:iLuffy,项目名称:ILuffy,代码行数:25,代码来源:Log4NetImpl.cs


示例13: LookupProperty

        /* \ \ 
           <summary>
           get property from log4net.Core.LoggingEvent
           </summary>
           <param name="property">the name of the property</param>
           <param name="loggingEvent">_The log4net.Core.LoggingEvent on
                                      which the pattern converter
                                      should be executed.</param>
           <returns>
           property value 
           </returns>                                                   */
        private object LookupProperty(string property, log4net.Core.LoggingEvent loggingEvent)
        {
            object propertyValue = string.Empty;
            propertyValue = loggingEvent.Properties[property];

            return propertyValue;
        }
开发者ID:danielmartind,项目名称:MSMQ_EMIAL,代码行数:18,代码来源:ReflectionLayout.cs


示例14: Append

        protected override void Append(log4net.Core.LoggingEvent loggingEvent)
        {
            if (loggingEvent == null || loggingEvent.ExceptionObject == null) return;

            var exceptionData = new ExceptionData
                                    {
                                        Exception = loggingEvent.ExceptionObject,
                                        Component = loggingEvent.LoggerName,
                                        Message = loggingEvent.RenderedMessage,
                                        UserId = UserId
                                    };
            if (loggingEvent.Level <= Level.Info)
            {
                exceptionData.Severity = ExceptionSeverity.None;
            }
            else if (loggingEvent.Level <= Level.Warn)
            {
                exceptionData.Severity = ExceptionSeverity.Warning;
            }
            else if (loggingEvent.Level <= Level.Error)
            {
                exceptionData.Severity = ExceptionSeverity.Error;
            }
            else if (loggingEvent.Level <= Level.Fatal)
            {
                exceptionData.Severity = ExceptionSeverity.Fatal;
            }

            ExceptronClient.SubmitException(exceptionData);

        }
开发者ID:Exceptron,项目名称:Exceptron.Log4Net,代码行数:31,代码来源:ExceptronAppender.cs


示例15: Log4NetLog

        /// <summary>
        /// Initializes a new instance of the <see cref="Log4NetLog"/> class.
        /// </summary>
        /// <param name="log">The log.</param>
        public Log4NetLog(log4net.ILog log)
        {
            if (log == null)
                throw new ArgumentNullException("log");

            m_Log = log;
        }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:11,代码来源:Log4NetLog.cs


示例16: Append

        /// <summary>
        /// Hinzufügen einer log-Nachricht zur Textbox im Formular
        /// </summary>
        protected override void Append(log4net.Core.LoggingEvent loggingEvent)
        {
            if (logFrm == null) return;

            string renderedMessage = this.RenderLoggingEvent(loggingEvent);
            logFrm.Append(renderedMessage);
        }
开发者ID:ThomasMentzel,项目名称:SlideShareCode,代码行数:10,代码来源:ToolboxAppender.cs


示例17: Append

 protected override void Append(log4net.Core.LoggingEvent loggingEvent)
 {
     string s = RenderLoggingEvent(loggingEvent);
     notifyIcon.BalloonTipText = s;
     notifyIcon.BalloonTipTitle = loggingEvent.Level.ToString();
     notifyIcon.ShowBalloonTip(1000);
 }
开发者ID:al-main,项目名称:sammy,代码行数:7,代码来源:NotifyIconAppender.cs


示例18: Append

 protected override void Append(log4net.Core.LoggingEvent loggingEvent)
 {
     switch (loggingEvent.Level.Name.ToLower())
     {
         case "alert":
         case "critical":
         case "emergency":
         case "error":
         case "fatal":
         case "severe":
             _taskLoggingHelper.LogError(loggingEvent.RenderedMessage);
             break;
         case "warn":
             _taskLoggingHelper.LogWarning(loggingEvent.RenderedMessage);
             break;
         case "info":
         case "notice":
             _taskLoggingHelper.LogMessage(MessageImportance.Normal, loggingEvent.RenderedMessage);
             break;
         case "debug":
         case "fine":
         case "finer":
         case "finest":
         case "trace":
         case "verbose":
         default:
             _taskLoggingHelper.LogMessage(MessageImportance.Low, loggingEvent.RenderedMessage);
             break;
     }
 }
开发者ID:Pablissimo,项目名称:nrconfig,代码行数:30,代码来源:BuildTaskLogAppender.cs


示例19: Append

		protected override void Append(log4net.Core.LoggingEvent loggingEvent) 
		{
			LogMessageModel.LogLevel logLevel;

			if(loggingEvent.Level.Value == infoLevel) {

				logLevel = LogMessageModel.LogLevel.INFO;

			} else if(loggingEvent.Level.Value == debugLevel) {

				logLevel = LogMessageModel.LogLevel.DEBUG;

			} else if(loggingEvent.Level.Value == errorLevel) {

				logLevel = LogMessageModel.LogLevel.ERROR;

			} else if(loggingEvent.Level.Value == warningLevel) {

				logLevel = LogMessageModel.LogLevel.WARNING;

			} else if(loggingEvent.Level.Value == fatalLevel) {

				logLevel = LogMessageModel.LogLevel.FATAL;
			
			} else {

				logLevel = LogMessageModel.LogLevel.UNKNOWN;
			}

			string logString = RenderLoggingEvent(loggingEvent);

            LogMessageModel message = new LogMessageModel(logLevel, logString);

            logViewModel.addMessage(message); 
		}
开发者ID:iejeecee,项目名称:mediaviewer,代码行数:35,代码来源:VisualAppender.cs


示例20: FeiHongTelCom

 public FeiHongTelCom(log4net.ILog logger)
 {
     if(logger!=null)
     {
         this.Logger = logger;
     }
 }
开发者ID:Bobom,项目名称:kuanmai,代码行数:7,代码来源:FeiHongTelCom.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# log4net.ILog类代码示例发布时间:2022-05-24
下一篇:
C# list类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap