Beispiel #1
0
 public void Trace(object message)
 {
     if (IsTraceEnabled)
     {
         loger.Log(LogLevel.Trace, message);
     }
 }
Beispiel #2
0
        public void Report(SpiderStatus status)
        {
            string       msg      = $"Left {status.Left} Success {status.Success} Error {status.Error} Total {status.Total} Dowload {status.AvgDownloadSpeed} Extract {status.AvgProcessorSpeed} Pipeline {status.AvgPipelineSpeed}";
            LogEventInfo theEvent = new LogEventInfo(NLog.LogLevel.Trace, "", msg);

            theEvent.Properties["UserId"]            = status.UserId;
            theEvent.Properties["TaskGroup"]         = status.TaskGroup;
            theEvent.Properties["Identity"]          = status.Identity;
            theEvent.Properties["Status"]            = status.Status;
            theEvent.Properties["Left"]              = status.Left;
            theEvent.Properties["Success"]           = status.Success;
            theEvent.Properties["Error"]             = status.Error;
            theEvent.Properties["Total"]             = status.Total;
            theEvent.Properties["AvgDownloadSpeed"]  = status.AvgDownloadSpeed;
            theEvent.Properties["AvgProcessorSpeed"] = status.AvgProcessorSpeed;
            theEvent.Properties["AvgPipelineSpeed"]  = status.AvgPipelineSpeed;

            if (SpiderConsts.SaveLogAndStatusToDb)
            {
                NetworkCenter.Current.Execute("nm", () =>
                {
                    _logger.Log(theEvent);
                });
            }
            else
            {
                _logger.Log(theEvent);
            }
        }
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="level">日志等级</param>
        /// <param name="content">日志内容</param>
        public void WriteLog(LogLevel level, ILogContent content)
        {
            var provider = GetFormatProvider();

            if (provider == null)
            {
                _logger.Log(ConvertTo(level), content);
                return;
            }
            _logger.Log(ConvertTo(level), provider, content);
        }
        public void Log(EventLevel eventLevel, TraceEvent eventData)
        {
            if (eventData == null)
            {
                return;
            }

            logger.Log(ConvertToLogLevel(eventLevel), FormatEventData(eventData));
        }
Beispiel #5
0
        public void Log(IIdentity identity, string message, LogLevel level, Exception e = null)
        {
            LogEventInfo theEvent = new LogEventInfo(GetNLogLevel(level), _logger.Name, message)
            {
                Exception = e
            };

            theEvent.Properties["Identity"] = identity == null ? "UNKNOW" : identity.Identity;
            _logger.Log(theEvent);
        }
Beispiel #6
0
        private void Log(LogEventInfo theEvent)
        {
            var alias = getAlias == null ? null : getAlias();

            if (alias != null)
            {
                theEvent.Properties["alias"] = alias + " - ";
            }
            loger.Log(theEvent);
        }
Beispiel #7
0
        /// <summary>
        /// 仅使用NLog写日志
        /// </summary>
        /// <param name="identity">唯一标识</param>
        /// <param name="message">信息</param>
        /// <param name="level">日志级别</param>
        /// <param name="exception">异常信息</param>
        public void NLog(string identity, string message, Level level, Exception exception = null)
        {
            LogEventInfo theEvent = new LogEventInfo(level.ToNLogLevel(), _nlogger.Name, message)
            {
                Exception = exception
            };

            theEvent.Properties["Identity"] = identity;
            theEvent.Properties["NodeId"]   = Env.NodeId;
            _nlogger.Log(theEvent);
        }
Beispiel #8
0
        private void Log(LogLevel info, string typeName, string message)
        {
            LogEventInfo eventInfo = new LogEventInfo(info, typeName, message)
            {
                TimeStamp = DateTime.UtcNow
            };

            SetEventInfoProperties(eventInfo);

            _logger.Log(eventInfo);
        }
Beispiel #9
0
        public static void Log(LogLevel level, string message, string path)
        {
            LogEventInfo logEventInfo = new LogEventInfo()
            {
                Level   = level,
                Message = message,
            };

            logEventInfo.Properties["path"] = path;
            Logger.Log(logEventInfo);
        }
Beispiel #10
0
 private void Log(NLogSelf.LogLevel level, int eventId, Exception exception, string message)
 {
     if (_innerLogger.IsEnabled(level))
     {
         var eventInfo = NLogSelf.LogEventInfo.Create(level, _innerLogger.Name, message);
         eventInfo.Exception                = exception;
         eventInfo.Properties["EventId"]    = eventId;
         eventInfo.Properties["EventId.Id"] = eventId;
         _innerLogger.Log(eventInfo);
     }
 }
Beispiel #11
0
        public void Log(ITask spider, string message, LogLevel level, Exception e = null)
        {
            LogEventInfo theEvent = new LogEventInfo(GetNLogLevel(level), _logger.Name, message)
            {
                Exception = e
            };

            theEvent.Properties["UserId"]    = spider == null ? "DotnetSpider" : spider.UserId;
            theEvent.Properties["TaskGroup"] = spider == null ? "Default" : spider.TaskGroup;
            theEvent.Properties["Identity"]  = spider == null ? "Default" : spider.Identity;
            _logger.Log(theEvent);
        }
        /// <inheritdoc/>
        public void Log(LogEvent logEvent)
        {
            NLog.LogLevel nLogLevel    = ConvertLogLevel(logEvent.LogLevel);
            var           logEventInfo = LogEventInfo.Create(nLogLevel, _logger.Name, logEvent.Exception, (IFormatProvider)_logger.Factory.DefaultCultureInfo, logEvent.Message, logEvent.PropertyValues);

            if (!string.IsNullOrWhiteSpace(logEvent.EventId))
            {
                logEventInfo.Properties["EventId"] = logEvent.EventId;
            }

            _logger.Log(logEventInfo);
        }
Beispiel #13
0
        public void Report(SpiderStatus status)
        {
            string       msg      = $"Left {status.Left} Success {status.Success} Error {status.Error} Total {status.Total} Thread {status.ThreadNum}";
            LogEventInfo theEvent = new LogEventInfo(NLog.LogLevel.Trace, "", msg);

            theEvent.Properties["UserId"]    = status.UserId;
            theEvent.Properties["TaskGroup"] = status.TaskGroup;
            theEvent.Properties["Identity"]  = status.Identity;
            theEvent.Properties["Status"]    = status.Status;
            theEvent.Properties["Message"]   = msg;

            if (SpiderConsts.SaveLogAndStatusToDb)
            {
                NetworkCenter.Current.Execute("nm", () =>
                {
                    _logger.Log(theEvent);
                });
            }
            else
            {
                _logger.Log(theEvent);
            }
        }
Beispiel #14
0
        public void Log(HttpContext httpContext, string body = "")
        {
            _logger = GetLogger(INFO);
            httpContext.Request.EnableRewind();
            var logEventInfo = new LogEventInfo(NLog.LogLevel.Info, _logger.Name, string.Empty);

            logEventInfo.Properties.Add("Host", Environment.MachineName);
            logEventInfo.Properties.Add("RequestedURL", httpContext.Request.GetDisplayUrl().ToString());
            logEventInfo.Properties.Add("Method", httpContext.Request.Method.ToString());
            logEventInfo.Properties.Add("ClientIP", httpContext.Connection.RemoteIpAddress);
            logEventInfo.Properties.Add("UserAgent", httpContext.Request.Headers["User-Agent"].ToString());
            logEventInfo.Properties.Add("RequestBody", body);
            _logger.Log(logEventInfo);
        }
Beispiel #15
0
        public void Log(LogLevel level, string message, Exception exception, LogProperty[] properties)
        {
            var logEvent = new NLogNamespace.LogEventInfo(
                LogHelper.TranslateLogLevel(level), _logger.Name, null, message, null, exception)
            {
                TimeStamp = LogCastContext.PreciseNow
            };

            if (properties != null && properties.Length > 0)
            {
                LogHelper.StoreLogProperties(logEvent, properties);
            }

            _logger.Log(logEvent);
        }
Beispiel #16
0
        public void Log(LogLevel level, IDictionary <string, object> state, Exception exception)
        {
            var nlogLogLevel = GetLogLevel(level);

            string message = null;

            if (state.ContainsKey("message"))
            {
                message = (string)state["message"];
            }

            var eventInfo = CreateLogEventInfo(nlogLogLevel, message, state, exception);

            _logger.Log(eventInfo);
        }
Beispiel #17
0
        private void InvokeConnectionStateChangedCallback(bool isConnected)
        {
            if (lastConnectionStateChangedValue.HasValue && lastConnectionStateChangedValue.Value == isConnected)
            {
                return;
            }

            lastConnectionStateChangedValue = isConnected;

            try
            {
                log.Log(isConnected ? LogLevel.Info : LogLevel.Warn, $"RedisClient.ConnectionState Changed to: {isConnected}");
                OnRedisConnectionStateChanged?.Invoke(this, new Core.Events.ProviderStateChangedEventArgs(isConnected));
            }
            catch (Exception e)
            {
                log.Error(e, "Failed to invoke ConnectionStateChanged");
            }
        }
Beispiel #18
0
        private void runLog(Exception exception, LogTag[] tag, string format, string function, object[] args, NLog.LogLevel level, string data)
        {
            LogEventInfo logInfo = createLogInfo(exception, tag, format, function, args, level, data);

            logger.Log(logInfo);
        }
        public void LogTrace(Exception exception, string format = "", params object[] values)
        {
            if (_logger.IsTraceEnabled)
            {
                var entry = CreateLogEntry(LogLevel.Trace, format, values);
                entry.Exception = exception;

                _logger.Log(entry);
            }
        }
Beispiel #20
0
 /// <inheritdoc />
 public void Log <TState>(LogLevel logLevel, string eventId, TState state, Exception exception,
                          Func <TState, Exception, string> formatter)
 {
     _logger.Log(logLevel, eventId, state, exception, formatter);
 }
Beispiel #21
0
 public void Log(LogLevel logLevel, string message, Exception exception = null, params object[] args)
 {
     logger.Log(logLevel, exception, message, args);
 }