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. // If there is an exception whilst processing the log request (for example when the connection with the // Internet disappears), try to log that exception. If that goes wrong too, fail silently. string url = context.Request.GetDisplayUrl(); if (LoggingUrlHelpers.IsLoggingUrl(url)) { try { ProcessRequest(context); } catch (Exception e) { try { _logger.LogInformation($"JSNLog: Exception while processing log request - {e}"); } catch { } } return; } // It was not a logging request await next(context); }
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 }
public async Task Invoke(IDictionary <string, object> environment) { IOwinContext context = new OwinContext(environment); // 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. if (LoggingUrlHelpers.IsLoggingUrl(context.Request.Uri.OriginalString)) { try { ProcessRequest(context); } catch { // An exception was thrown while processing a log request. // Just eat it here, seeing there doesn't seem to be an easy and reliable way // to log the exception. } return; } // It was not a logging request await _next.Invoke(environment); }
public void IsLoggingUrl_NoUrlsConfigured_CodeConfig() { JavascriptLogging.SetJsnlogConfiguration(null, null); Assert.True(LoggingUrlHelpers.IsLoggingUrl("/jsnlog.logger")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.logger")); Assert.False(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.css")); }
public void IsLoggingUrl_NoUrl() { string configXml = @" <jsnlog></jsnlog> "; CommonTestHelpers.SetConfigCache(configXml, null); Exception ex = Assert.Throws <ArgumentNullException>(() => LoggingUrlHelpers.IsLoggingUrl(null)); }
public void IsLoggingUrl_NoUrlsConfigured() { string configXml = @" <jsnlog></jsnlog> "; CommonTestHelpers.SetConfigCache(configXml, null); Assert.True(LoggingUrlHelpers.IsLoggingUrl("/jsnlog.logger")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.logger")); Assert.False(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.css")); }
public async Task Invoke(HttpContext context) { string url = context.Request.GetDisplayUrl(); if (LoggingUrlHelpers.IsLoggingUrl(url)) { ProcessRequest(context); return; } await _next(context); }
public void IsLoggingUrl_DefaultConfigured_NoAppenderUrlsConfigured() { string configXml = @" <jsnlog defaultAjaxUrl=""/jsnlogger""></jsnlog> "; CommonTestHelpers.SetConfigCache(configXml, null); Assert.True(LoggingUrlHelpers.IsLoggingUrl("/jsnlogger")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("/abc/def/jsnlogger")); Assert.False(LoggingUrlHelpers.IsLoggingUrl("/jsnlog.logger")); Assert.False(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.logger")); Assert.False(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.css")); }
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)) { ProcessRequest(context); return; } // It was not a logging request await next(context); }
public async Task Invoke(IDictionary <string, object> environment) { IOwinContext context = new OwinContext(environment); // 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. if (LoggingUrlHelpers.IsLoggingUrl(context.Request.Uri.OriginalString)) { ProcessRequest(context); return; } // It was not a logging request await _next.Invoke(environment); }
public void IsLoggingUrl_NoDefaultConfigured_AppenderUrlsConfiguredWithTilde() { string configXml = @" <jsnlog> <ajaxAppender url=""~/jsn2logger"" /> </jsnlog> "; CommonTestHelpers.SetConfigCache(configXml, null); Assert.True(LoggingUrlHelpers.IsLoggingUrl("/jsn2logger")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("//abc.com/jsn2logger?a=b;c=d")); // url of the default appender should also be regarded as a logging url Assert.True(LoggingUrlHelpers.IsLoggingUrl("/jsnlog.logger")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.logger")); Assert.False(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.css")); }
public void IsLoggingUrl_NoDefaultConfigured_AppenderUrlsConfigured() { string configXml = @" <jsnlog> <ajaxAppender name=""a1"" url=""/jsn2logger"" /> </jsnlog> "; CommonTestHelpers.SetConfigCache(configXml, null); Assert.True(LoggingUrlHelpers.IsLoggingUrl("/jsn2logger")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("//abc.com/jsn2logger?a=b;c=d")); // Should also the url of the default appender Assert.True(LoggingUrlHelpers.IsLoggingUrl("/jsnlog.logger")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.logger")); Assert.False(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.css")); }
public void IsLoggingUrl_DefaultConfigured_MultipleAppenderUrlsConfigured() { string configXml = @" <jsnlog defaultAjaxUrl=""/jsnlogger""> <ajaxAppender name=""a1"" url=""/jsn2logger"" /> <ajaxAppender name=""a2"" url =""/jsn3logger"" /> </jsnlog> "; CommonTestHelpers.SetConfigCache(configXml, null); Assert.True(LoggingUrlHelpers.IsLoggingUrl("/jsn2logger")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("//abc.com/jsn2logger?a=b;c=d")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("/jsn3logger")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("//abc.com/jsn3logger?a=b;c=d")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("/jsnlogger")); Assert.True(LoggingUrlHelpers.IsLoggingUrl("/abc/def/jsnlogger")); Assert.False(LoggingUrlHelpers.IsLoggingUrl("/jsnlog.logger")); Assert.False(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.logger")); Assert.False(LoggingUrlHelpers.IsLoggingUrl("http://abc.com/jsnlog.css")); }