public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, LogEventInfo ev) { var contextData = new ContextData(ev.GetContextData()); if (ev.Exception != null) contextData.SetException(ev.Exception); var builder = client.CreateEvent(contextData); if (ev.Exception == null) { builder.SetSource(ev.LoggerName); builder.SetProperty(Event.KnownDataKeys.Level, ev.Level.Name); } builder.Target.Date = ev.TimeStamp; if (!String.IsNullOrWhiteSpace(ev.FormattedMessage)) builder.SetMessage(ev.FormattedMessage); if (ev.Exception != null) builder.SetSource(ev.LoggerName); var tagList = ev.GetTags(); if (tagList.Count > 0) builder.AddTags(tagList.ToArray()); foreach (var p in ev.Properties.Where(kvp => !_ignoredEventProperties.Contains(kvp.Key.ToString(), StringComparer.OrdinalIgnoreCase))) builder.SetProperty(p.Key.ToString(), p.Value); return builder; }
public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, LogEventInfo ev) { if (client == null) throw new ArgumentNullException(nameof(client)); var contextData = new ContextData(ev.GetContextData()); if (ev.Exception != null) contextData.SetException(ev.Exception); var builder = client.CreateEvent(contextData); builder.Target.Date = ev.TimeStamp; builder.SetSource(ev.LoggerName); var properties = ev.Properties .Where(kvp => !_ignoredEventProperties.Contains(kvp.Key.ToString(), StringComparer.OrdinalIgnoreCase)) .ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value, StringComparer.OrdinalIgnoreCase); object value; if (properties.TryGetValue("@value", out value)) { try { builder.SetValue(Convert.ToDecimal(value)); properties.Remove("@value"); } catch (Exception) {} } object stackingKey; if (properties.TryGetValue(Event.KnownDataKeys.ManualStackingInfo, out stackingKey)) { try { builder.SetManualStackingKey(stackingKey.ToString()); properties.Remove(Event.KnownDataKeys.ManualStackingInfo); } catch (Exception) { } } if (ev.Exception == null) builder.SetProperty(Event.KnownDataKeys.Level, ev.Level.Name); if (!String.IsNullOrWhiteSpace(ev.FormattedMessage)) builder.SetMessage(ev.FormattedMessage); var tagList = ev.GetTags(); if (tagList.Count > 0) builder.AddTags(tagList.ToArray()); foreach (var p in properties) builder.SetProperty(p.Key, p.Value); return builder; }