Beispiel #1
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!IsEnabled(logLevel) || formatter == null)
            {
                return;
            }

            try
            {
                var logSerializer = serializers.GetAppropriateSerializer(logLevel, state, exception);

                if (logSerializer == null)
                {
                    //todo
                    throw new NotImplementedException("Unable to find an appropriate serializer for the log event");
                }

                var(serializedLog, timestamp) = logSerializer.Serialize(Name, logLevel, eventId, state, exception, formatter);

                client.Send(serializedLog, timestamp);
            }
            catch (Exception ex)
            {
                ConsoleColor.Red.OutputMessage($"Unable to log message at {DateTimeOffset.UtcNow}, due to {ex.Message}.{Environment.NewLine}{ex.StackTrace}");
            }
        }