Esempio n. 1
0
        public async Task Invoke(HttpContext context)
        {
            // If this is a logging request (based on its url), do the logging and don't pass on the request
            // to the rest of the pipeline.
            string url = context.Request.GetDisplayUrl();

            if (LoggingUrlHelpers.IsLoggingUrl(url))
            {
                await LoggerRequestHelpers.ProcessLoggerRequestAsync(context, _logger);

                return;
            }

            // It was not a logging request

            JsnlogConfiguration jsnlogConfiguration = JavascriptLogging.GetJsnlogConfiguration();

            if (!jsnlogConfiguration.insertJsnlogInHtmlResponses)
            {
                // If automatic insertion is not enabled, simply call the rest of the pipeline and return.
                await _next(context);

                return;
            }

#if NETFRAMEWORK
            throw new Exception(
                      "Automatic insertion of JSNLog into HTML pages is not supported in netstandard2.0. " +
                      $"Upgrade to netstandard2.1 or for other options see {SiteConstants.InstallPageUrl}");
#else
            // Check other content for HTML
            await HandleHtmlInjection(context);
#endif
        }
 /// <summary>
 /// Normally, an ASP.NET 5 app would simply call this to insert JSNLog middleware into the pipeline.
 /// Note that the loggingAdapter is required, otherwise JSNLog can't hand off log messages.
 /// It can live without a configuration though (it will use default settings).
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="loggingAdapter"></param>
 /// <param name="jsnlogConfiguration"></param>
 public static void UseJSNLog(this IApplicationBuilder builder,
                              ILoggingAdapter loggingAdapter, JsnlogConfiguration jsnlogConfiguration = null)
 {
     JavascriptLogging.SetJsnlogConfiguration(jsnlogConfiguration, loggingAdapter);
     builder.UseMiddleware <JSNLogMiddleware>();
 }