Documentation Menu

Sending log requests to a non default URL

By default, the jsnlog.js library sends all log requests to the URL /jsnlog.logger.

To send all log requests to another URL, the following needs to be done:

  1. Configure jsnlog.js so it sends to the new url.
  2. Check the handlers in your web.config.
  3. If you use OWIN, check its configuration.
  4. If needed, allow cross domain requests.

1. Configure jsnlog.js

To change the default URL that log requests are sent to:

You can further override the default for each Ajax Appender:

  • In your server side configuration - set the url attribute of the AjaxAppender.
  • Or in JavaScript - set the url option of the AjaxAppender.

2. Check web.config

Check the handlers in the <system.web> and/or <system.webServer> sections of your web.config file. These contain a wildcard matching the url of log requests.

3. Check OWIN configuration

If you do not use OWIN, skip this step.

The OWIN middleware component looks at the URL of all incoming requests to see if it is a logging request. If it is, it processes the logging information in the request and then short circuits it, so it doesn't travel on to the downstream components.

If you changed the URL where log requests are sent, you want to make sure that the OWIN middleware component looks for the right URL.

If you use server side configuration to configure that new URL, this is all taken care off. The OWIN middleware component looks at the server side configuration to find out what URLs to look for.

However, if you configure the new URL in JavaScript, the OWIN middleware component has no way of knowing about the new URL.

To solve this, simply set the defaultAjaxUrl attribute on the <jsnlog> / JsnlogConfiguration configuration element. This will tell the OWIN middleware component about the new URL.

4. Allow cross domain requests

You may want to send your log requests to a site with a domain that is different from the site where they originate. For example, you have multiple sites with their own domains, and you want all log messages to go to a single common URL.

An issue is that by default, browsers do not allow JavaScript (such as jsnlog.js) to send AJAX requests to a domain different from the site domain.

To make cross domain requests possible, JSNLog implements the CORS protocol.

For security reasons, you have to explicitly nominate the domains that JSNLog should accept requests from. All other domains will still be blocked.

To do this, set the corsAllowedOriginsRegex attribute of the <jsnlog> / JsnlogConfiguration configuration element to a regular expression that matches all accepted domains (test your regular expression).

For example, this jsnlog element allows requests from my-abc-domain.com, my-xyz-domain.com and all their sub domains, both over http and https:

<jsnlog corsAllowedOriginsRegex="^https?:\/\/([a-z0-9]+[.])*(my-abc-domain[.]com|my-xyz-domain[.]com)$" >
</jsnlog>
JavascriptLogging.SetJsnlogConfiguration(
  new JsnlogConfiguration {
      corsAllowedOriginsRegex="^https?:\\/\\/([a-z0-9]+[.])*(my-abc-domain[.]com|my-xyz-domain[.]com)$"
  });

For a working example, see the JSNLogDemo_Log4Net_CORS project in the simple working demos solution on GitHub.

CORS, Request Ids, and IE8/9

If you use both cross domain log requests and Request Ids, you will not receive request ids from IE8 and IE9 (usage share).

This is because CORS is implemented on IE8 and IE9 with the Microsoft specific XDomainRequest, which does not allow custom request headers - and request ids are sent using a request header.

IE10 and later are standards compliant by adding CORS support to XMLHTTPRequest, which does allow custom request headers.

It may be possible to fix this issue in JSNLog. However, this has little priority seeing the age and dwindling usage share of IE8 and IE9.