mperdeck / jsnlog

JSNLog for .Net. Combines jsnlog.js client side logging with .Net server side component to receive log messages and pass them to the server side logging package. Configure loggers in web.config.
jsnlog.com
MIT License
190 stars 38 forks source link

Exception inside of NLog ${message} #160

Closed sdyrby closed 6 years ago

sdyrby commented 6 years ago

Hi,

I'm trying to configure my simple JSNLog setup with NLog, running ASP.Net Core 2. For some reason I seem to get the stacktrace/exception inside of the NLog ${message}, and not the ${exception:format=toString}. Is this intentional, or can I change this?

Eg:

FATAL | 2018-01-19 09:58:11.3225 | ClientRoot[0HLAV3B17VGBA:00000004] | "stack": "Error: such exception... wow...\n    at viewWrappedDebugError (http://localhost:4200/vendor.bundle.js:142706:15)\n    at callWithDebugContext (http://localhost:4200/vendor.bundle.js:147776:15)\n    at Object.debugHandleEvent [as handleEvent] (http://localhost:4200/vendor.bundle.js:147354:12)\n    at dispatchEvent (http://localhost:4200/vendor.bundle.js:142898:21)\n    at http://localhost:4200/vendor.bundle.js:143509:20\n    at HTMLButtonElement.<anonymous> (http://localhost:4200/vendor.bundle.js:185570:53)\n    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.bundle.js:6564:31)\n    at Object.onInvokeTask (http://localhost:4200/vendor.bundle.js:138172:33)\n    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.bundle.js:6563:36)\n    at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.bundle.js:6331:47)", "message": "such exception... wow...", "name": "Error", "logData": "Uncaught Exception" | 

I also can't seem to make it break lines on \n. Tried a NLog REgex, but it absolutely will not accept \\n. This migth be an NLog issue though.

Eg:

layout="${uppercase:${level}} | ${longdate} | ${logger}[${aspnet-TraceIdentifier}] | ${replace:inner=${message}:searchFor=\\n:replaceWith=\n:regex=true} | ${exception:format=toString}"/>

I'd really like my logs to look like the following:

ERROR | 2018-01-06 10:21:59.9956 | ClassName[RJS:00000022] | Error message. | url: https://some/url | System.FormatException: The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.
   at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style)
   at Plass.Domidont.SagsObjektModel.TObjPart.set_CprNrVaerdi(String value)
mperdeck commented 6 years ago

JSNLog doesn't make a distinction between logging a string with exception info and logging any other string. At the moment, this is baked into the product, it is not configurable.

Re. your second point, I'm not sure this is a solution, but you can write an event handler that modifies the string with log info before it goes to the server side logging package. See http://jsnlog.com/Documentation/JavascriptLogging/OnLogging

sdyrby commented 6 years ago

Thank you the good reply 👍