Exemplo n.º 1
0
        /// <summary>
        /// Get logger
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="mode"></param>
        /// <param name="renderingOptions"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static ILogger GetLogger <T>(Func <string, LogEventLevel, bool> filter,
                                            LogEventSendMode mode = LogEventSendMode.Customize,
                                            RenderingConfiguration renderingOptions = null)
        {
            var provider = TouchProvider();

            return(provider == null ? NullLogger.Instance : provider.GetLogger <T>(filter, mode, renderingOptions));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get logger
        /// </summary>
        /// <param name="type"></param>
        /// <param name="minLevel"></param>
        /// <param name="mode"></param>
        /// <param name="renderingOptions"></param>
        /// <returns></returns>
        public static ILogger GetLogger(Type type, LogEventLevel minLevel,
                                        LogEventSendMode mode = LogEventSendMode.Customize,
                                        RenderingConfiguration renderingOptions = null)
        {
            var provider = TouchProvider();

            return(provider == null ? NullLogger.Instance : provider.GetLogger(type, minLevel, mode, renderingOptions));
        }
Exemplo n.º 3
0
 public static IFutureLogger GetFutureLogger <T>(LogEventSendMode mode = LogEventSendMode.Customize,
                                                 RendingConfiguration renderingOptions = null,
                                                 [CallerMemberName] string memberName  = null,
                                                 [CallerFilePath] string filePath      = null,
                                                 [CallerLineNumber] int lineNumber     = 0)
 {
     return(GetLogger <T>(mode, renderingOptions).ToFuture(memberName, filePath, lineNumber));
 }
Exemplo n.º 4
0
        public static ILogger GetLogger(string categoryName,
                                        LogEventSendMode mode = LogEventSendMode.Customize,
                                        RendingConfiguration renderingOptions = null)
        {
            var provider = TouchProvider();

            return(provider == null ? NullLogger.Instance : provider.GetLogger(categoryName, mode, renderingOptions));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Get future logger
 /// </summary>
 /// <param name="type"></param>
 /// <param name="minLevel"></param>
 /// <param name="filter"></param>
 /// <param name="mode"></param>
 /// <param name="renderingOptions"></param>
 /// <param name="memberName"></param>
 /// <param name="filePath"></param>
 /// <param name="lineNumber"></param>
 /// <returns></returns>
 public static IFutureLogger GetFutureLogger(Type type, LogEventLevel minLevel, Func <string, LogEventLevel, bool> filter,
                                             LogEventSendMode mode = LogEventSendMode.Customize,
                                             RenderingConfiguration renderingOptions = null,
                                             [CallerMemberName] string memberName    = null,
                                             [CallerFilePath] string filePath        = null,
                                             [CallerLineNumber] int lineNumber       = 0)
 {
     return(GetLogger(type, minLevel, filter, mode, renderingOptions).ToFuture(memberName, filePath, lineNumber));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Create a new instance of <see cref="LoggerBase"/>
        /// </summary>
        /// <param name="sourceType"></param>
        /// <param name="minimumLevel"></param>
        /// <param name="loggerStateNamespace"></param>
        /// <param name="filter"></param>
        /// <param name="sendMode"></param>
        /// <param name="renderingOptions"></param>
        /// <param name="logPayloadSender"></param>
        protected LoggerBase(
            Type sourceType,
            LogEventLevel minimumLevel,
            string loggerStateNamespace,
            Func <string, LogEventLevel, bool> filter,
            LogEventSendMode sendMode,
            RenderingConfiguration renderingOptions,
            ILogPayloadSender logPayloadSender)
        {
            StateNamespace             = loggerStateNamespace;
            TargetType                 = sourceType ?? typeof(object);
            MinimumLevel               = minimumLevel;
            SendMode                   = sendMode;
            _filter                    = filter ?? TrueFilter;
            _logPayloadSender          = logPayloadSender ?? throw new ArgumentNullException(nameof(logPayloadSender));
            _messageParameterProcessor = MessageParameterProcessorCache.Get();
            _upstreamRenderingOptions  = renderingOptions ?? new RenderingConfiguration();

            AutomaticPayload       = new LogPayload(sourceType, loggerStateNamespace, Enumerable.Empty <LogEvent>());
            ManuallyPayload        = new LogPayload(sourceType, loggerStateNamespace, Enumerable.Empty <LogEvent>());
            CurrentManuallyTransId = DateTime.Now.Ticks;
            _manuallyLogEventDescriptors.TryAdd(CurrentManuallyTransId, new List <ManuallyLogEventDescriptor>());
        }
Exemplo n.º 7
0
 /// <summary>
 /// Fire atuomativally
 /// </summary>
 /// <returns></returns>
 public LogEventContext FireAutomatically()
 {
     SendMode = LogEventSendMode.Automatic;
     return(this);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Write
        /// </summary>
        /// <param name="logTrack"></param>
        /// <param name="level"></param>
        /// <param name="exception"></param>
        /// <param name="messageTemplate"></param>
        /// <param name="sendMode"></param>
        /// <param name="callerInfo"></param>
        /// <param name="context"></param>
        /// <param name="messageTemplateParameters"></param>
        public void Write(LogTrack?logTrack, LogEventLevel level, Exception exception, string messageTemplate, LogEventSendMode sendMode, ILogCallerInfo callerInfo,
                          LogEventContext context = null, params object[] messageTemplateParameters)
        {
            if (!IsEnabled(level))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(messageTemplate))
            {
                return;
            }
            var cleanMessageTemplateParameters = ArgsHelper.CleanUp(messageTemplateParameters);
            var logEventId = TouchLogEventId(logTrack, StateNamespace);

            if (IsManuallySendMode(sendMode))
            {
                ParseAndInsertLogEvenDescriptorManually(logEventId, level, exception, messageTemplate, callerInfo, context, cleanMessageTemplateParameters);
            }
            else
            {
                ParseAndInsertLogEventIntoQueueAutomatically(logEventId, level, exception, messageTemplate, callerInfo, context, cleanMessageTemplateParameters);
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Is manually send mode
 /// </summary>
 /// <param name="modeInEvent"></param>
 /// <returns></returns>
 protected virtual bool IsManuallySendMode(LogEventSendMode modeInEvent) =>
 modeInEvent != LogEventSendMode.Automatic &&
 (SendMode == LogEventSendMode.Customize && modeInEvent == LogEventSendMode.Manually || SendMode == LogEventSendMode.Manually);
Exemplo n.º 10
0
 /// <inheritdoc />
 public AspNetCoreLogger(Type sourceType, LogEventLevel minimumLevel, string loggerStateNamespace, Func <string, LogEventLevel, bool> filter,
                         LogEventSendMode sendMode, RenderingConfiguration renderingOptions, ILogPayloadSender logPayloadSender, IHttpContextAccessor httpContextAccessor)
     : base(sourceType, minimumLevel, loggerStateNamespace, filter, sendMode, renderingOptions, logPayloadSender)
 {
     HttpContext = httpContextAccessor?.HttpContext;
 }
Exemplo n.º 11
0
 public void Write(LogEventId eventId, LogEventLevel level, Exception exception, string messageTemplate, LogEventSendMode sendMode, ILogCallerInfo callerInfo,
                   LogEventContext context = null, params object[] messageTemplateParameters)
 {
     if (!IsEnabled(level))
     {
         return;
     }
     if (string.IsNullOrWhiteSpace(messageTemplate))
     {
         return;
     }
     if (IsManuallySendMode(sendMode))
     {
         ParseAndInsertLogEvenDescriptorManually(eventId ?? new LogEventId(), level, exception, messageTemplate, callerInfo, context, messageTemplateParameters);
     }
     else
     {
         ParseAndInsertLogEventIntoQueueAutomatically(eventId ?? new LogEventId(), level, exception, messageTemplate, callerInfo, context, messageTemplateParameters);
     }
 }