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:
- Configure jsnlog.js so it sends to the new url.
- If needed, allow cross domain requests (CORS).
1. Configure jsnlog.js
To change the default URL that log requests are sent to:
-
In your server side configuration
-
set the defaultAjaxUrl attribute of the
JSNLog
configuration element. -
Or in JavaScript
-
set the defaultAjaxUrl option of the
global JL object
.
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. 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 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>
// Use in Configure method in Startup class var jsnlogConfiguration = 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.
JSNLog does not support CORS on IE8/9
IE8 and IE9 require additional code to support CORS. Because of their very low market share, JSNLog does not support CORS on these browsers. If you use CORS, then jsnlog.js running on these browsers will not send log messages to the server.