/// <summary> /// Converts the LogData to LogEventInfo. /// </summary> /// <param name="logData">The log data.</param> /// <returns></returns> public static global::NLog.LogEventInfo ToLogEvent(this LogData logData) { var logEvent = new global::NLog.LogEventInfo(); logEvent.TimeStamp = DateTime.Now; logEvent.Level = logData.LogLevel.ToLogLevel(); logEvent.LoggerName = logData.Logger; logEvent.Exception = logData.Exception; logEvent.FormatProvider = logData.FormatProvider; logEvent.Message = logData.Message; logEvent.Parameters = logData.Parameters; if (logData.Properties != null) { foreach (var property in logData.Properties) { logEvent.Properties[property.Key] = property.Value; } } logEvent.Properties["CallerMemberName"] = logData.MemberName; logEvent.Properties["CallerFilePath"] = logData.FilePath; logEvent.Properties["CallerLineNumber"] = logData.LineNumber; return(logEvent); }
protected override void Write(global::NLog.LogEventInfo logEvent) { #if DEBUG var message = Layout.Render(logEvent); if (_filterRegex == null || (_filterRegex != null && _filterRegex.Match(message).Success)) { this.WriteToTrace(logEvent.Level, message); } #endif }
protected override void WriteLine(string line, params string[] args) { if (this.metricType == null || this.metricName == null) { return; } var loggerName = string.Format("Metrics.Text.{0}.{1}", this.metricType, this.metricName); var logEvent = LogEventInfo.Create(LogLevel.Info, loggerName, string.Format(line, args)); logEvent.Properties.Add("MetricType", CleanFileName(metricType)); logEvent.Properties.Add("MetricName", CleanFileName(metricName)); LogManager.GetLogger(loggerName).Log(logEvent); }
private LogEventInfo GetLogEvent(string logger, DateTime timestamp, string metricType, string metricName, IEnumerable <CSVReport.Value> values) { var logEvent = new LogEventInfo(LogLevel.Info, logger, GetValues(timestamp, values)); logEvent.Properties.Add("MetricType", CleanFileName(metricType)); logEvent.Properties.Add("MetricName", CleanFileName(metricName)); logEvent.Properties.Add("Date", timestamp.ToString("u")); logEvent.Properties.Add("Ticks", timestamp.Ticks.ToString("D")); foreach (var value in values) { logEvent.Properties.Add(value.Name, value.FormattedValue); } return(logEvent); }
protected override string GetFormattedMessage(global::NLog.LogEventInfo logEvent) { var wrappedEvent = new LogEventWrapper(logEvent); PrepareEvent(wrappedEvent); var builder = new StringBuilder(); using (var writer = XmlWriter.Create(builder, new XmlWriterSettings() { OmitXmlDeclaration = true, Encoding = Encoding.UTF8, Indent = true, IndentChars = "\t" })) { var element = new XElement("message", new XAttribute("time", logEvent.TimeStamp.ToUniversalTime().ToString("u", CultureInfo.InvariantCulture)), new XAttribute("source", logEvent.LoggerName), new XAttribute("level", logEvent.Level), new XAttribute("message", logEvent.FormattedMessage) ); if (logEvent.Exception != null) { element.Add(FormatException(logEvent.Exception)); } object extendedInfo; if (logEvent.Properties.TryGetValue("extendedInfo", out extendedInfo) && extendedInfo != null) { element.Add(new XElement("extendedInfo", extendedInfo)); } foreach (var interceptor in LogEventInterceptorProviders.Providers.GetInterceptors()) { interceptor.Render(wrappedEvent, element); } element.Save(writer); } return(builder.ToString()); }
/// <summary> /// Converts the LogData to LogEventInfo. /// </summary> /// <param name="logData">The log data.</param> /// <returns></returns> public static global::NLog.LogEventInfo ToLogEvent(this LogData logData) { var logEvent = new global::NLog.LogEventInfo(); logEvent.TimeStamp = DateTime.Now; logEvent.Level = logData.LogLevel.ToLogLevel(); logEvent.LoggerName = logData.Logger; logEvent.Exception = logData.Exception; logEvent.FormatProvider = logData.FormatProvider; logEvent.Message = logData.Message; logEvent.Parameters = logData.Parameters; if (logData.Properties != null) foreach (var property in logData.Properties) logEvent.Properties[property.Key] = property.Value; logEvent.Properties["CallerMemberName"] = logData.MemberName; logEvent.Properties["CallerFilePath"] = logData.FilePath; logEvent.Properties["CallerLineNumber"] = logData.LineNumber; return logEvent; }
protected void Log(global::NLog.LogLevel logLevel, Exception exception, string message, params object[] parameters) { var logEvent = new global::NLog.LogEventInfo(logLevel, Name, null, message, parameters, exception); logger.Log(typeof(NLogLogger), logEvent); }
protected void Log(global::NLog.LogLevel logLevel, Exception exception, string message, params object[] parameters) { var logEvent = new global::NLog.LogEventInfo(logLevel, Name, null, message, parameters, exception); logger.Log(logEvent); }