Inheritance: ICanCreateJsonFields
コード例 #1
0
        public static void UseJSNLog(this IApplicationBuilder builder,
                                     ILoggerFactory loggerFactory, JsnlogConfiguration jsnlogConfiguration = null)
        {
            var loggingAdapter = new LoggingAdapter(loggerFactory);

            UseJSNLog(builder, loggingAdapter, jsnlogConfiguration);
        }
コード例 #2
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
        }
コード例 #3
0
        public static void SetJsnlogConfiguration(
            JsnlogConfiguration jsnlogConfiguration, ILoggingAdapter loggingAdapter = null)
        {
#if NET40
            SetJsnlogConfiguration(() => XmlHelpers.RootElement(), jsnlogConfiguration, loggingAdapter);
#else
            SetJsnlogConfigurationWithoutWebConfig(jsnlogConfiguration, loggingAdapter);
#endif
        }
コード例 #4
0
        public static void SetJsnlogConfiguration(
            JsnlogConfiguration jsnlogConfiguration, ILoggingAdapter loggingAdapter = null)
        {
#if !RunningAspNetCore
            // When using ASP Net CORE, we never use the web.config file
            SetJsnlogConfiguration(() => XmlHelpers.RootElement(), jsnlogConfiguration, loggingAdapter);
#else
            SetJsnlogConfigurationWithoutWebConfig(jsnlogConfiguration, loggingAdapter);
#endif
        }
コード例 #5
0
ファイル: JavascriptLogging.cs プロジェクト: matthid/jsnlog
        public static void SetJsnlogConfiguration(
            JsnlogConfiguration jsnlogConfiguration, ILoggingAdapter loggingAdapter = null)
        {
#if NETFRAMEWORK
            // When using ASP Net CORE with a Net Framework target (such as net47),
            // assume XmlHelpers.RootElement() will always be null.
            SetJsnlogConfiguration(() => XmlHelpers.RootElement(), jsnlogConfiguration, loggingAdapter);
#else
            SetJsnlogConfigurationWithoutWebConfig(jsnlogConfiguration, loggingAdapter);
#endif
        }
コード例 #6
0
        internal static void SetJsnlogConfigurationWithoutWebConfig(
            JsnlogConfiguration jsnlogConfiguration, ILoggingAdapter loggingAdapter = null)
        {
            _jsnlogConfiguration = jsnlogConfiguration;

            // Never allow setting the logger to null.
            // If user only set the configuration (leaving logger at null), don't change the logger.

            if (loggingAdapter != null)
            {
                _logger = loggingAdapter;
            }
        }
コード例 #7
0
        // All unit tests run under DNX451
#if NET40 || DNX451
        // Seam used for unit testing. During unit testing, gets an xml element created by the test.
        // During production get the jsnlog element from web.config.
        //
        // >>>>>>
        // Note that calling this method with a given xe is a way to cache that xe's config
        // for the next call to GetJsnlogConfiguration().
        internal static JsnlogConfiguration GetJsnlogConfiguration(Func <XmlElement> lxe)
        {
            if (_jsnlogConfiguration == null)
            {
                XmlElement xe = lxe();
                if (xe != null)
                {
                    _jsnlogConfiguration = XmlHelpers.DeserialiseXml <JsnlogConfiguration>(xe);
                }
            }

            return(GetJsnlogConfigurationWithoutWebConfig());
        }
コード例 #8
0
        // All unit tests run under DNX451
#if NET40 || DNX451
        internal static void SetJsnlogConfiguration(
            Func <XmlElement> lxe, JsnlogConfiguration jsnlogConfiguration, ILoggingAdapter logger = null)
        {
            // Always allow setting the config to null, because GetJsnlogConfiguration retrieves web.config when config is null.
            if (jsnlogConfiguration != null)
            {
                XmlElement xe = lxe();
                if (xe != null)
                {
                    throw new ConflictingConfigException();
                }
            }

            SetJsnlogConfigurationWithoutWebConfig(jsnlogConfiguration, logger);
        }
コード例 #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            // Configure JSNLog
            var jsnlogConfiguration = new JsnlogConfiguration(); // See jsnlog.com/Documentation/Configuration
            app.UseJSNLog(new LoggingAdapter(loggerFactory), jsnlogConfiguration);

            app.UseStaticFiles();

            // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            // Create a catch-all response
            app.Run(async (context) =>
            {
                try
                {
                    var logger = loggerFactory.CreateLogger("Catchall Endpoint");
                    logger.LogInformation("No endpoint found for request {path}", context.Request.Path);
                   // await context.Response.WriteAsync("No endpoint found - try /api/todo.");
                }
                catch (Exception ex)
                {

                }
            });
        }
コード例 #10
0
 /// <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>();
 }
コード例 #11
0
 /// <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>();
 }
コード例 #12
0
ファイル: JavascriptLogging.cs プロジェクト: mperdeck/jsnlog
 public static void SetJsnlogConfiguration(
     JsnlogConfiguration jsnlogConfiguration, ILoggingAdapter loggingAdapter = null)
 {
     SetJsnlogConfigurationWithoutWebConfig(jsnlogConfiguration, loggingAdapter);
 }