Documentation Menu


1. Install NuGet package

These NuGet packages install JSNLog and an adapter that works with your server side logging package. They assume that you have already installed a server side logging package.

These packages contain dependencies for both ASP.NET 4.x and ASP.NET Core. However, versions below 2.8.60318.667 of the NuGet Package Manager installed in Visual Studio do not support this.

To check your Nuget version and upgrade if needed:

  1. In Visual Studio, open Tools | Extensions and Updates...;
  2. Click Updates (in left hand menu);
  3. If an update of NuGet Package Manager is available, click Update.
Your ASP.NET version Your Logging Package Install this package
ASP.NET 4.x Log4Net Install-Package JSNLog.Log4Net
ASP.NET 4.x NLog Install-Package JSNLog.NLog
ASP.NET 4.x Elmah Install-Package JSNLog.Elmah
ASP.NET 4.x Serilog Install-Package JSNLog.Serilog
ASP.NET 4.x Common.Logging Install-Package JSNLog.CommonLogging
ASP.NET Core any Click here

If your logging package is not listed here, install the version for Common.Logging and then install a Common.Logging adapter for your logging package.

2. Serilog only

This package assumes that you have created a global logger. For example:

var log = new LoggerConfiguration()
// Set global logger, so JSNLog can access it. Log.Logger = log;

A good place for this would be the Application_Start handler in your Global.asax.cs.

3. Add JSNLog to your pages

Call JSNLog's Configure method in your pages, before any script tags that load JavaScript that use JSNLog loggers. This generates a script tag that loads the jsnlog.min.js JavaScript library (how to stop this).

  • For Razor (MVC3+), use:
    @*Add to your pages before the script tags*@

    Your _Layout.cshtml or _Layout.vbhtml would probably be a good place for this.

  • For WebForms, use:
    @*Add to your pages before the script tags*@
    <%= JSNLog.JavascriptLogging.Configure() %>

    Your master page would probably be a good place for this.

Take these steps if you cannot call Configure, for example if your pages are flat files that are not generated by MVC or WebForms.

4. OWIN only

A working demo is in project JSNLogDemo_Log4Net_OWIN

  1. Add JSNLog to your OWIN pipeline in your Startup class:

    using JSNLog;
    public class Startup { public void Configuration(IAppBuilder app) { ... // Short circuits log requests from the jsnlog.js client library and // passes the log data on to the server side logging package. app.UseJSNLog(); ... } }
  2. Update your web.config - Remove the definitions that make JSNLog work as an HTTP Handler, and add a definition that sends all log requests to the OWIN handler:

            <!-- Remove this line -->
                            <add verb="*" path="*.logger" type="JSNLog.LoggerHandler, JSNLog" />
            <!-- Remove these lines -->
                            <add name="LoggerHandler" verb="*" path="*.logger" type="JSNLog.LoggerHandler, JSNLog" resourceType="Unspecified" preCondition="integratedMode" />
                            <add name="LoggerHandler-Classic" path="*.logger" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode" />
            Add this line. 
            If you configure JSNLog to send log request to a url that 
            does NOT end in .logger (how), change the path attribute below.
                            <add name="Owin" verb="" path="*.logger" 
                 type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb"/>

  3. Add package - If you haven't already done so, add the Microsoft.Owin.Host.SystemWeb package:
    Install-Package Microsoft.Owin.Host.SystemWeb

5. Add your company's logo

If you are using JSNLog in your company's web site, please let us know.

Adding your logo to the bottom of our web site gives your company some free exposure, and tells others that you are happy using it.

6. Start logging >>