public static void ConfigureTLoggerServices(this IServiceCollection serviceCollection)
        {
            IWebLogger wl = new WebLogger();

            serviceCollection.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            serviceCollection.AddSingleton(typeof(IWebLogger), wl);
        }
예제 #2
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var request  = context.HttpContext.Request;
            var activity = $"{request.Path}-{request.Method}";
            var dict     = new Dictionary <string, object>();

            foreach (var key in context.RouteData.Values?.Keys)
            {
                dict.Add($"RouteData-{key}", (string)context.RouteData.Values[key]);
            }
            var details = WebLogger.GetLogEntry(_product, _layer, activity, context.HttpContext, dict);

            var logger = context.HttpContext.RequestServices.GetService(typeof(IWebLogger));

            if (logger is WebLogger)
            {
                _tracker = new PerformanceTracker(details, (WebLogger)logger);
            }
            base.OnActionExecuting(context);
        }
예제 #3
0
        public PerformanceTracker(LogEntry entry, WebLogger logger)
        {
            _sw     = Stopwatch.StartNew();
            _entry  = entry;
            _logger = logger;
            DateTime beginTime = DateTime.Now;

            if (_entry.AdditionalInfo == null)
            {
                _entry.AdditionalInfo = new Dictionary <string, object>()
                {
                    { "Started", beginTime.ToString(CultureInfo.InvariantCulture) }
                }
            }
            ;
            else
            {
                _entry.AdditionalInfo.Add(
                    "Started", beginTime.ToString(CultureInfo.InvariantCulture));
            }
        }