Exemple #1
0
        /// <summary>
        /// Writes the specified LogData to NLog.
        /// </summary>
        /// <param name="logData">The log data.</param>
        public static void WriteLog(LogData logData) {
            var logEvent = logData.ToLogEvent();
            var name = logData.Logger ?? typeof(NLogWriter).FullName;

            var logger = global::NLog.LogManager.GetLogger(name);
            logger.Log(logEvent);
        }
Exemple #2
0
 /// <summary>
 /// Writes the specified LogData to the underlying logger.
 /// </summary>
 /// <param name="logData">The log data.</param>
 public void WriteLog(LogData logData) {
     var eventType = ToEventType(logData.LogLevel);
     if (logData.Parameters != null && logData.Parameters.Length > 0)
         _traceSource.Value.TraceEvent(eventType, 1, logData.Message, logData.Parameters);
     else
         _traceSource.Value.TraceEvent(eventType, 1, logData.Message);
 }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogBuilder" /> class.
        /// </summary>
        /// <param name="logLevel">The starting trace level.</param>
        /// <param name="logger">The delegate to write logs to.</param>
        /// <exception cref="System.ArgumentNullException">writer</exception>
        public LogBuilder(LogLevel logLevel, ILogger logger) {
            if (logger == null)
                throw new ArgumentNullException(nameof(logger));

            _logger = logger;
            _data = new LogData {
                LogLevel = logLevel,
                FormatProvider = CultureInfo.InvariantCulture
            };
        }
Exemple #4
0
 /// <summary>
 /// Writes the log.
 /// </summary>
 /// <param name="logData">The log data.</param>
 public void WriteLog(LogData logData) {
     NLogWriter.WriteLog(logData);
 }