예제 #1
0
        public Log4NetProxy(log4net.ILog logger)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");

            _logger = logger;
        }
 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);
     }
 }
예제 #3
0
        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);
            }
        }
예제 #4
0
 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;
 }
        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 });
            }
        }
        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();
        }
예제 #7
0
 /// <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);
     });
 }
예제 #8
0
 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());
         }
     }
 }
예제 #9
0
        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;
        }
예제 #10
0
        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;
        }
        /*
         * 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("-",""));
            }
        }
예제 #12
0
        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;
        }
예제 #13
0
        /* \ \ 
           <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;
        }
        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);

        }
예제 #15
0
        /// <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;
        }
        /// <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);
        }
예제 #17
0
 protected override void Append(log4net.Core.LoggingEvent loggingEvent)
 {
     string s = RenderLoggingEvent(loggingEvent);
     notifyIcon.BalloonTipText = s;
     notifyIcon.BalloonTipTitle = loggingEvent.Level.ToString();
     notifyIcon.ShowBalloonTip(1000);
 }
예제 #18
0
 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;
     }
 }
예제 #19
0
		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); 
		}
예제 #20
0
 public FeiHongTelCom(log4net.ILog logger)
 {
     if(logger!=null)
     {
         this.Logger = logger;
     }
 }
예제 #21
0
        protected override void Append(log4net.Core.LoggingEvent loggingEvent)
        {
            string msg = base.RenderLoggingEvent(loggingEvent);

            switch (loggingEvent.Level.Name)
            {
                case "FATAL":
                case "ERROR":
                    MessageBox.Show(msg, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case "WARN":
                    MessageBox.Show(msg, "警示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    break;

                case "INFO":
                    MessageBox.Show(msg, "資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;

                case "DEBUG":
                    //debug不應顯示訊息
                    break;

            }
        }
        public OrchardLog4netLogger(log4net.Core.ILogger logger, OrchardLog4netFactory factory) {
            OrchardHostContainerRegistry.RegisterShim(this);
            Logger = logger;
            Factory = factory;

            _shellSettings = new Lazy<ShellSettings>(LoadSettings);
        }
예제 #23
0
 protected override void Convert(System.IO.TextWriter writer , log4net.Core.LoggingEvent loggingEvent)
 {
     if (null != Option) {
         WriteObject(writer , loggingEvent.Repository , LookupProperty(Option , loggingEvent));
     } else {
         WriteDictionary(writer , loggingEvent.Repository , loggingEvent.GetProperties());
     }
 }
예제 #24
0
 protected override void Append(log4net.Core.LoggingEvent loggingEvent)
 {
     m_Logs.Enqueue(loggingEvent);
     if (m_Logs.Count >= 25 && m_Logs.Count % 25 == 0)
     {
         Prune();
     }
 }
 /// <summary>
 /// 通过反射获取传入的日志对象的某个属性的值
 /// </summary>
 /// <param name="property"></param>
 /// <returns></returns>
 private object LookupProperty(string property, log4net.Core.LoggingEvent loggingEvent)
 {
     object propertyValue = string.Empty;
     PropertyInfo propertyInfo = loggingEvent.MessageObject.GetType().GetProperty(property);
     if (propertyInfo != null)
         propertyValue = propertyInfo.GetValue(loggingEvent.MessageObject, null);
     return propertyValue;
 }
예제 #26
0
 public Subtitles(log4net.ILog log = null)
 {
     Log = log;
     items = new List<SubtitleItem>();
     rwLock = new ReaderWriterLockSlim();
     SubtitleLocations = new List<string>();
     track = -1;
 }
예제 #27
0
 protected override void Convert(System.IO.TextWriter writer, log4net.Core.LoggingEvent loggingEvent)
 {
     LogContent logMessage = loggingEvent.MessageObject as LogContent;
     if (logMessage != null)
     {
         writer.Write(logMessage.UserId);
     }
 }
예제 #28
0
        public OrchardLog4netLogger(log4net.Core.ILogger logger, OrchardLog4netFactory factory)
        {
            OrchardHostContainerRegistry.RegisterShim(this);
            Logger = logger;
            Factory = factory;

             _shellSettings = new Lazy<ShellSettings>(LoadSettings, System.Threading.LazyThreadSafetyMode.PublicationOnly);
        }
예제 #29
0
 /// <summary>
 /// 初始化jquery的引用,目地是asp.net从bin目录下拷贝到应用跟目录,获得目录的html访问权限
 /// </summary>
 /// <param name="globalServer">HttpServerUtility对象Server</param>
 /// <param name="ILog1">ILog对象</param>
 public void initJquery(System.Web.HttpServerUtility globalServer, log4net.ILog ILog1)
 {
     string result = moveHTML(globalServer.MapPath("bin/jqueryJs"), globalServer.MapPath("jqueryJs"));
     if (result != null)
     {
         ILog1.Info("jquery初始化失败:" + result);
     }
 }
예제 #30
0
 public MsilSymbolManager(ICommandLine commandLine, IFilter filter, log4net.ILog logger, Strategy.ITrackedMethodStrategyManager trackedMethodStrategyManager)
 {
     _commandLine = commandLine;
     _filter = filter;
     _logger = logger;
     _trackedMethodStrategyManager = trackedMethodStrategyManager;
     _methods = new Dictionary<int, MethodDefinition>();
 }