コード例 #1
0
ファイル: AsyncProcessZLogger.cs プロジェクト: sambsp/ZLogger
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            var factory = CreateLogEntry <TState> .factory;

            if (factory != null)
            {
                var info  = new LogInfo(categoryName, DateTimeOffset.UtcNow, logLevel, eventId, exception);
                var entry = factory.Invoke(state, info);
                logProcessor.Post(entry);
            }
            else
            {
                var info = new LogInfo(categoryName, DateTimeOffset.UtcNow, logLevel, eventId, exception);
                if (StateTypeDetector <TState> .IsInternalFormattedLogValues || state == null)
                {
                    // null state automatically converted to FormattedLogValues struct.
                    logProcessor.Post(StringFormatterEntry <TState> .Create(info, state, exception, formatter));
                }
                else
                {
                    // sometimes state has context(like HttpContext), it require to format in scope.
                    var message = formatter(state, exception);
                    logProcessor.Post(StringFormatterEntry <string> .Create(info, message, exception, ReturnStringStateFormatter));
                }
            }
        }
コード例 #2
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            var factory = CreateLogEntry <TState> .factory;

            if (factory != null)
            {
                var info  = new LogInfo(categoryName, DateTimeOffset.UtcNow, logLevel, eventId, exception);
                var entry = factory.Invoke(state, info);
                logProcessor.Post(entry);
            }
            else
            {
                var info = new LogInfo(categoryName, DateTimeOffset.UtcNow, logLevel, eventId, exception);
                logProcessor.Post(StringFormatterEntry <TState> .Create(info, state, exception, formatter));
            }
        }