public static ILoggerFactory AddSimpleGelf(this ILoggerFactory loggerFactory, GelfLoggerConfig config)
 {
     _config = config;
     loggerFactory.AddProvider(new SimpleGelfProvider(config));
     GelfSimpleHttpClient.Configure(config);
     return(loggerFactory);
 }
Пример #2
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            var message = new GelfMessage
            {
                ShortMessage = formatter(state, exception),
                Host         = _gelfLoggerConfig.LogSource,
                Level        = GetLevel(logLevel),
                Timestamp    = GelfSimpleHttpClient.GetTimestamp(),
                Logger       = _name,
                Exception    = exception?.ToString(),
                EventId      = eventId.Id,
                EventName    = eventId.Name
            };

            GelfSimpleHttpClient.Send(message);
        }
        private static void LogGelfLogErrorModel(string guid, LogErrorModel logErrorModel)
        {
            if (logErrorModel == null)
            {
                return;
            }

            var message = new GelfMessage
            {
                ShortMessage  = logErrorModel.Message,
                Host          = _config.LogSource,
                Level         = SyslogSeverity.Error,
                Timestamp     = GelfSimpleHttpClient.GetTimestamp(),
                Logger        = "LoggerFactoryExtensions",
                Exception     = logErrorModel._Exception?.ToString(),
                CorrelationId = guid,
                Data          = logErrorModel.Data
            };

            GelfSimpleHttpClient.Send(message);
        }