Esempio n. 1
0
        private static void AddTags(this LogEventInfo ev, params string[] tags)
        {
            if (tags == null || tags.Length == 0)
            {
                return;
            }

#if PORTABLE
            var list = ev.GetTags() ?? new HashSet <string>(StringComparer.OrdinalIgnoreCase);
#else
            var list = ev.GetTags() ?? new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);
#endif
            foreach (string tag in tags)
            {
                list.Add(tag);
            }

            ev.Properties[Tags] = list;
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, LogEventInfo ev)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var data        = ev.GetContextData();
            var contextData = data != null ? new ContextData(data) : new ContextData();

            if (ev.Exception != null)
            {
                contextData.SetException(ev.Exception);
            }

            var builder = client.CreateEvent(contextData);

            builder.Target.Date = ev.TimeStamp;
            builder.SetSource(ev.LoggerName);

            if (ev.Properties.Count > 0)
            {
                foreach (var property in ev.Properties)
                {
                    string propertyKey = property.Key.ToString();
                    if (_ignoredEventProperties.Contains(propertyKey, StringComparer.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    if (propertyKey.Equals("@value", StringComparison.OrdinalIgnoreCase))
                    {
                        try {
                            builder.SetValue(Convert.ToDecimal(property.Value));
                        } catch (Exception) { }

                        continue;
                    }

                    if (propertyKey.Equals(Event.KnownDataKeys.ManualStackingInfo, StringComparison.OrdinalIgnoreCase))
                    {
                        try {
                            builder.SetManualStackingKey(property.Value.ToString());
                        } catch (Exception) { }

                        continue;
                    }

                    builder.SetProperty(propertyKey, property.Value);
                }
            }

            if (ev.Exception == null)
            {
                builder.SetType(Event.KnownTypes.Log);
                builder.SetProperty(Event.KnownDataKeys.Level, ev.Level.Name);
            }
            else
            {
                builder.SetType(Event.KnownTypes.Error);
            }

            if (!String.IsNullOrWhiteSpace(ev.FormattedMessage))
            {
                builder.SetMessage(ev.FormattedMessage);
            }

            var tags = ev.GetTags();

            if (tags != null)
            {
                builder.AddTags(tags.ToArray());
            }

            return(builder);
        }