Ejemplo n.º 1
0
        public EventBuilder CreateEvent()
        {
            var builder = _logger?.CreateEvent();

            builder.SetSource("Kugar.Core.Log.ExceptionlessFactory");

            return(_logger?.CreateEvent());
        }
Ejemplo n.º 2
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!this.IsEnabled(logLevel))
            {
                return;
            }
            var builder = exception != null?_client.CreateException(exception)
                              : _client.CreateEvent().SetType(Exceptionless.Models.Event.KnownTypes.Log);

            builder.SetMessage(formatter(state, exception));
            builder.SetProperty(Exceptionless.Models.Event.KnownDataKeys.Level, ConvertLogLevel(logLevel).ToString());
            builder.SetSource(_name);

            var logEntity = state as IExceptionLessLogEntity;

            if (logEntity != null)
            {
                if (logEntity.Data != null)
                {
                    builder.AddObject(logEntity.Data);
                }
                if (logEntity.Tags != null)
                {
                    builder.AddTags(logEntity.Tags);
                }
                if (logEntity.User != null)
                {
                    builder.SetUserIdentity(logEntity.User);
                }
            }
            builder.Submit();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Track a view navigation using just a name.
        /// </summary>
        /// <param name="name">Name of the view.</param>
        public void OnViewNavigation(string name)
        {
            // need to consider whether to just use feature event
            // and tag it with view specific properties.
            var eventBuilder = _exceptionlessClient
                               .CreateEvent()
                               .SetType("PageView")
                               .SetMessage(name);

            eventBuilder.Submit();
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
 public EventBuilder CreateEvent() => _client?.CreateEvent();
Ejemplo n.º 7
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);
        }