3

I am having trouble getting JsNlog to work with Angular 2 (latest full release). I installed JsNlog into my project (empty client web application in Visual Studio 2015) via npm and then set it up in a service but I get the error "XHR error (403 Forbidden) loading" when trying to use one of the methods. Please can anyone tell me what I am doing wrong?

Below is the code:

My Service:

import { Injectable, Component } from '@angular/core';
import JL from 'jsnlog';

@Injectable()

export class JSLoggerService
{
 constructor()
 {
 }

log(msg: string)
{
    JL('Angular').trace(msg);
}

debug(msg: string)
{
    JL('Angular').debug(msg);
}

info(msg: string)
{
    JL('Angular').info(msg);
}

warn(msg: string)
{
    JL('Angular').warn(msg);
}

error(msg: string)
{
     JL('Angular').error(msg);
}
}

In a component (just parts relevant to jsnlog):

import { JSLoggerService } from './shared/services/jslogger.service';

export class AppComponent
{
    constructor(private _jsnlog: JSLoggerService)
    {
      _jsnlog.log("hi");
    }
}

Systemjs.config.js (just parts relevant to jsnlog):

          map: {
             'jsnlog': 'npm:jsnlog'
         }

package.json (just parts relevant to jsnlog):

          dependencies: {
             'jsnlog': '2.20.1'
         }

app.module.ts (just parts relevant to jsnlog):

          import { JSLoggerService } from './shared/services/jslogger.service';

@NgModule({
providers: [
    JSLoggerService
],
bootstrap:[ AppComponent]
})
LanceM
  • 1,888
  • 4
  • 23
  • 41
  • Possible duplicate of [What is the correct syntax for importing JSNLog using ES6?](https://stackoverflow.com/questions/35684035/what-is-the-correct-syntax-for-importing-jsnlog-using-es6) – Graham Jun 27 '17 at 15:25

1 Answers1

0

I am the author of JSNLog. I finally got round to adding a page to jsnlog.com describing how to add JSNLog to an Angular 2+ app: http://jsnlog.com/Documentation/HowTo/Angular2Logging

user1147862
  • 4,096
  • 8
  • 36
  • 53
  • Thanks very much for that. I love Jsnlog but I wasn't able to wait for this in my current project so I had to come up with my own solution (call a wcf rest service that uses nlog to write the file). I will look at that when I get a chance. – LanceM Jun 27 '17 at 18:26