JSNlog Exception formatting problem has surfaced

Encountering an issue with JSNlog and Nlog regarding the format of Exceptions from JSNlog. All error logs are being written out in JSON, but when an exception is thrown from JavaScript, the system encodes the %message property as JSON as well, causing the main JSON to become invalid.

The configuration for the Nlog.config file for this appender is:

layout='{"Enviroment":"${aspnet-application:variable=Enviroment}","CreatedOn": "${longdate:universalTime=true}", "WindowsIdentity":"${aspnet-user-identity:jsonEncode=true}","Application":"${AppName}", "Level":"${level}", ${message}}' />

The configuration for the web.config for JSNlog is:

serverSideMessageFormat=""UserAgent": "%userAgent", "SessionId": "%requestId", "URL":"%url", "UserAddress": "%userHostAddress", "Message": "%message""

With this configuration, it works fine for normal logging calls but fails on fatalException calls due to the resulting invalid JSON structure. For example:

{"Enviroment":"Dev", "CreatedOn": "2014-09-24 23:58:42.1734", "WindowsIdentity":"XXXr","Application":"LoggingTest", "Level":"Fatal", "UserAgent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36", "SessionId": "befn1iy4mlxqowppwepf104z", "URL":"/LoggingTest/jsnlog.logger", "UserAddress": "10.247.224.202", "Message": "{"stack":"TypeError: undefined is not a function\n    at Log (http://zue-v-86a32393.vpc-am.aws.shell-cloud.com/LoggingTest/:58:16)\n    at HTMLInputElement.onclick (http:/XXXX/LoggingTest/:66:141)","message":"undefined is not a function","name":"TypeError","logData":"JS Fatal Exception"}"}

Attempting to remove quotes around messages resolves the issue for fatalException calls but breaks JSON validity for other log types.

If anyone has a solution or suggestion on handling this problem with proper formatting of exceptions from fatalException calls, your insights would be greatly appreciated.

Answer №1

Hi there, I'm the creator of JSNLog.

The issue at hand stems from a bug within JSNLog. When logging an object on the client side, it gets sent as a JSON string like { "x": 44 }. This includes quotes. However, when logging a simple string, it is transmitted without surrounding quotes and any quotes inside the string are not escaped - thus causing compatibility issues with JSON objects.

While this setup typically functions fine for simple string log entries, problems arise when attempting to log valid JSON objects.

Although untested, it's likely that using your original configuration to log a string containing a quote on the client will result in the same error experienced with fatalException.

To resolve this issue, I have implemented a new property called %jsonmessage, which properly encloses and escapes strings. You can utilize this property in your existing configuration to achieve the desired outcome you had with fatalException.

I'll provide updates on any developments in the comments section below this answer.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to pass the double-clicked row as a parameter to a function, when the row is dynamically created in the code?

I am facing an issue with adding rows to an empty table using a button and attaching a dblclick event listener to each row. The challenge arises when I need to execute a function that requires the specific row being double-clicked. In tables already popu ...

Tips for utilizing Express.js Request and Response as parameter types in JSDoc

One of my functions requires Express Request and Response objects as arguments. function doSomething(request, response) { // perform actions } Is there a way to utilize jsdoc to specify the types of request and response? UPDATE: I believe this questio ...

Executing ESM-Enabled Script in Forever

Is it possible to execute a script using the option -r esm in Forever? When I try to run the configuration below, I encounter an error message that reads: Unexpected token import. Here is the configuration: { "uid": "app", "script": "index.js", "s ...

The monorepo contains TypeScript files with a .js extension, causing confusion for IDEs that are unable to recognize TypeScript code within them

After cloning the React monorepo from GitHub and opening it as a new project in WebStorm IDE, I encountered an issue. It turns out that all the .js files in this repository are actually written in TypeScript, causing confusion for the IDE. For instance: / ...

What are the drawbacks of calling async/await within a fresh Promise() constructor?

I have implemented the async.eachLimit function to manage the maximum number of operations concurrently. const { eachLimit } = require("async"); function myFunction() { return new Promise(async (resolve, reject) => { eachLimit((await getAsyncArray ...

Comparing strings while handling null values

Whenever I need to compare two strings, I typically use the following code: if(!string.IsNullOrEmpty(str1) && str1.Equals(str2)){ //they are equal, do my thing } This code takes care of handling the null case first. I am wondering if there i ...

Encountering difficulties when fetching JSON data with the Ionic AngularJS framework

Currently, I am following Lynda's tutorial on Ionic framework and have encountered an issue while working on backend coding. After generating the app, I proceeded to open the www/js/app.js file to include a controller with the following code: .contro ...

Creating personalized selections with the bootstrap combobox: a guide

I created a form that displays options as I type, but I want to add icons next to the dropdown items and have them link to specific pages when clicked. For example, I'd like an icon next to "alabama" that appears when I type "a" and directs me to a ce ...

Implementing the bootstrap dynamic modal in Laravel Blade for delete confirmation is an effective way to enhance user

I'm aiming to utilize a bootstrap modal for delete confirmation. However, I'm facing an issue where I need to pass a dynamic variable (containing the item ID) value to the bootstrap modal in order to submit a post request to delete that specific ...

Sharing object beyond ng-repeat loop

As someone who is new to AngularJs, I am currently working on implementing table filtering and deleting the correct object when the delete button is clicked. This is my previous implementation before filtering: $scope.rowIndex = -1; $scope.selectRow = fu ...

What is the best way to merge multiple arrays nested within another array while removing the final character from each word?

We have a 2D array: let userGroup = [ ['user1-', 'user2-', 'user3-'], ['user4-', 'user5-', 'user6-'], ['user7-', 'user8-', 'user9-'] ]; How can we c ...

The EntityType 'Employee' is missing a key definition. Please specify the key for this EntityType

In my Solution.Models.Worker code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; namespace Solution.Models { public class Worker { public int ID { get; set; } public ...

Having trouble converting JSON to an object with Newtonsoft.Json library

I have encountered an issue with deserializing a sample JSON received from a service using C#. { "columns": [ "empid", "employeename", "currentAllocation", "Dept head", ...

What is the process for getting involved with npm commands?

Here is an excerpt from my package.json file: "scripts": { "cpFile": cp ../template/index.js /src/view/home/ } When I try to run the command: npm run cpFile fileName.js I expect it to execute: cp ../template/index.js /src/view/home/fileName.js How ...

Utilizing Angular's mixed binding feature with curly braces in queryParams

Can anyone help me with binding my component's field to the [queryParams] attribute? I tried using this code: <a routerLink="/{{getMyLink()}}" [queryParams]="{ navSource: {{navSource}} }" /> The issue I'm facing is that the outer braces a ...

Transforming attributes into a JSON format

Click here to view my JSFiddle example function testing() { foo = canvas.getObjects(); bar = JSON.stringify(canvas.getObjects()); console.log(foo); console.log(bar); } After examining my JSFiddle link above, it appears that JSON.stringify() is al ...

Mapping objects from one to another using AngularJS

I need to create a mapping of the $scope.filters object to a new variable called criteria, based on whether the original fields are null or not. For example: $scope.filters = { name: 'myName', lastName: null, age: null, } The desir ...

Tips on inputting a correct date into the database with individual fields for day, month, and

In my project, I have a registration form that includes three dropdown lists for day, month, and year. I dynamically populate the day dropdown list using codebehind: private void Add_Date() { ddl_dat.Items.Add(new ListItem("-Date-", "-1")); for (i ...

The hierarchical structure in the DOM that mirrors an HTML table

While working on code to navigate the DOM for a table, I encountered an unexpected surprise. The DOM (specifically in FF) did not align with my initial expectations. Upon investigation, it appears that FF has automatically inserted a tbody along with sever ...

What's the best approach to achieve security in C# - LinkDemand vs. SecurityCritical or something

After conducting a security check on my application, I received the following warning: The method 'Parser.GenerateJeffpReport(string)' contains a call to 'Process.Start()' which is subjected to a LinkDemand. This could potentially ...