Exemplo n.º 1
0
        /// <summary>
        /// 记录日志
        /// </summary>
        /// <typeparam name="TState"></typeparam>
        /// <param name="logLevel"></param>
        /// <param name="eventId"></param>
        /// <param name="state"></param>
        /// <param name="exception"></param>
        /// <param name="formatter"></param>
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            try
            {
                var message      = formatter(state, exception);
                var source       = $"{_categoryName}{(eventId != 0 ? ":" + eventId : "")}";
                var eventBuilder = default(EventBuilder);
                if (exception != null)
                {
                    eventBuilder = ExceptionlessClient
                                   .Default
                                   .CreateException(exception)
                                   .SetSource(source)
                                   .SetMessage(message);
                }
                else
                {
                    var exlessLogLevel = Exceptionless.Logging.LogLevel.Trace;
                    switch (logLevel)
                    {
                    case LogLevel.Trace:
                        exlessLogLevel = Exceptionless.Logging.LogLevel.Trace;
                        break;

                    case LogLevel.Information:
                        exlessLogLevel = Exceptionless.Logging.LogLevel.Info;
                        break;

                    case LogLevel.Warning:
                        exlessLogLevel = Exceptionless.Logging.LogLevel.Warn;
                        break;

                    case LogLevel.Error:
                        exlessLogLevel = Exceptionless.Logging.LogLevel.Error;
                        break;

                    case LogLevel.Critical:
                        exlessLogLevel = Exceptionless.Logging.LogLevel.Fatal;
                        break;

                    default:
                        exlessLogLevel = Exceptionless.Logging.LogLevel.Debug;
                        break;
                    }
                    eventBuilder = ExceptionlessClient
                                   .Default
                                   .CreateLog(message, exlessLogLevel)
                                   .SetSource(source)
                                   .SetException(exception);
                }
                eventBuilder.SetProperty("ServerEndPoint", LoggingUtility.GetAddressIP());
                eventBuilder.Submit();
            }
            catch { }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 记录日志
        /// </summary>
        /// <typeparam name="TState"></typeparam>
        /// <param name="logLevel"></param>
        /// <param name="eventId"></param>
        /// <param name="state"></param>
        /// <param name="exception"></param>
        /// <param name="formatter"></param>
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            try
            {
                var message        = formatter(state, exception);
                var source         = $"{_categoryName}";
                var exlessLogLevel = Exceptionless.Logging.LogLevel.Trace;
                switch (logLevel)
                {
                case LogLevel.Trace:
                    exlessLogLevel = Exceptionless.Logging.LogLevel.Trace;
                    break;

                case LogLevel.Information:
                    exlessLogLevel = Exceptionless.Logging.LogLevel.Info;
                    break;

                case LogLevel.Warning:
                    exlessLogLevel = Exceptionless.Logging.LogLevel.Warn;
                    break;

                case LogLevel.Error:
                    exlessLogLevel = Exceptionless.Logging.LogLevel.Error;
                    break;

                case LogLevel.Critical:
                    exlessLogLevel = Exceptionless.Logging.LogLevel.Fatal;
                    break;

                default:
                    exlessLogLevel = Exceptionless.Logging.LogLevel.Debug;
                    break;
                }
                var eventBuilder = ExceptionlessClient.Default
                                   .CreateLog(message, exlessLogLevel)
                                   .SetSource(source)
                                   .SetException(exception);

                if (eventId != null)
                {
                    eventBuilder.SetProperty("Event", $"{eventId.ToString()}");
                }

                var serverAndPoint = LoggingUtility.GetAddressIP();
                if (!string.IsNullOrEmpty(serverAndPoint))
                {
                    eventBuilder.SetProperty("ServerEndPoint", serverAndPoint);
                }

                eventBuilder.Submit();
            }
            catch { }
        }