Esempio n. 1
0
            public void Log(
                LogLevel logLevel,
                int eventId,
                object state,
                Exception exception,
                Func <object, Exception, string> formatter)
            {
                var nLogLogLevel = GetLogLevel(logLevel);
                var message      = string.Empty;

                if (formatter != null)
                {
                    message = formatter(state, exception);
                }
                else
                {
                    message = LogFormatter.Formatter(state, exception);
                }
                if (!string.IsNullOrEmpty(message))
                {
                    var eventInfo = LogEventInfo.Create(nLogLogLevel, _logger.Name, message, exception);
                    eventInfo.Properties["EventId"] = eventId;
                    _logger.Log(eventInfo);
                }
            }
        private static void LogEvent(NLogger logger, NLogLevel level, string logSource, Exception exception, string message, params object[] parameters)
        {
            var logEvent = new LogEventInfo(level, logger.Name, null, message, parameters, exception);

            logEvent.Properties["logSource"] = logSource;
            logger.Log(logEvent);
        }
Esempio n. 3
0
 private static void LogEvent(NLogger logger, NLogLevel level, string logSource, Exception exception, object message)
 {
     if (logger.IsEnabled(level))
     {
         var logEvent = new LogEventInfo(level, logger.Name, null, "{0}", new[] { message }, exception);
         logEvent.Properties["logSource"]     = logSource;                                         // TODO logSource is the same as logger.Name, now adding twice
         logEvent.Properties["SourceContext"] = Context?.Sender?.Path?.ToString() ?? string.Empty; // Same as Serilog
         logger.Log(logEvent);
     }
 }
 public void Trace(string message)
 {
     logger.Log(LogLevel.Trace, message);
 }
Esempio n. 5
0
 public void Write(LogLevel level, string message)
 {
     _logger.Log(level.ToLogEventLevel(), message);
 }
Esempio n. 6
0
        // TODO: callsite showing the framework logging classes/methods
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            var nLogLogLevel = ConvertLogLevel(logLevel);

            if (!IsEnabled(nLogLogLevel))
            {
                return;
            }

            string message = formatter != null?formatter(state, exception) : state.ToString();

            if (string.IsNullOrEmpty(message))
            {
                return;
            }

            var eventInfo = global::NLog.LogEventInfo.Create(nLogLogLevel, _logger.Name, message);

            eventInfo.Exception = exception;
            if (eventId.Id != 0)
            {
                eventInfo.Properties["EventId"] = eventId;
            }

            var logData = state as LogData;

            if (logData != null)
            {
                eventInfo.Properties["CallerMemberName"] = logData.MemberName;
                eventInfo.Properties["CallerFilePath"]   = logData.FilePath;
                eventInfo.Properties["CallerLineNumber"] = logData.LineNumber;

                foreach (var property in logData.Properties)
                {
                    eventInfo.Properties[property.Key] = property.Value;
                }
            }
            else
            {
                var logDictionary = state as IDictionary <string, object>;
                if (logDictionary != null)
                {
                    foreach (var property in logDictionary)
                    {
                        eventInfo.Properties[property.Key] = property.Value;
                    }
                }
            }

            var scopes = CurrentScopeStack.Reverse().ToArray();

            foreach (var scope in scopes)
            {
                var scopeData = scope as IDictionary <string, object>;
                if (scopeData == null)
                {
                    continue;
                }

                foreach (var property in scopeData)
                {
                    eventInfo.Properties[property.Key] = property.Value;
                }
            }

            _populateAdditionalLogEventInfo?.Invoke(state, scopes, eventInfo);

            _logger.Log(eventInfo);
        }
Esempio n. 7
0
 /// <summary>
 /// Called when [log debug].
 /// </summary>
 /// <param name="message">The message.</param>
 protected override void OnLogDebug(object message)
 {
     //AssignLogEntry(_logger, LogLevel.Debug, message.ToString(), LogType.Exception, LogCategory.Normal, null);
     _logger.Log(LogLevel.Debug, message.ToString());
 }
 /// <summary>
 /// Write an entry to the registered log writers.
 /// </summary>
 /// <param name="logLevel">The severity level of the log entry.</param>
 /// <param name="message">
 /// The message for the log entry, optionally in a <see cref="String.Format(string, object[])"/>
 /// form when there are <paramref name="arguments"/>.</param>
 /// <param name="arguments">Optional arguments to format the <paramref name="message"/>.
 /// </param>
 public void Log(LogLevel logLevel, string message, params object[] arguments)
 => logger.Log(TranslateLogLevel(logLevel), message, arguments);
Esempio n. 9
0
 public void Log(LogLevel level, string message, long?messageId = null)
 {
     _log.Log(global::NLog.LogLevel.FromOrdinal((int)level), message);
 }
Esempio n. 10
0
 public void Log <T>(LoggingLevel level, T value)
 {
     nlogLogger.Log(LoggingLevelMapper.GetNLogLevel(level), value);
 }
Esempio n. 11
0
 public void Log(Burrows.Logging.LogLevel level, object message)
 {
     _log.Log(GetNLogLevel(level), message);
 }