Is there a log4net for javascript?

I want to register an asp.net web application, framework 4.0. I use log4net as my logging device, and RollingFileAppender works fine with code.

can log4net log javascript? if so, how? if not, how do you guys register javascript?

+4
source share
4 answers

Here is log4javascript , which is based on log4j (like log4net).

+5
source

There are several options.

I liked the lumberjack, but I can not find it at the moment.

+5
source

I just use Console.log. It logs data in firefox / chrome console.

http://getfirebug.com/wiki/index.php/Console_API#console.log.28object.5B.2C_object.2C_....5D.29

+2
source

Alternatively, you can simply implement the REST POST function in the .Net controller, call it via AJAX in your JavaScript code.

Example:

.Net Controller Funktion

private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // POST: LogFromJavaScript [AllowAnonymous] [HttpPost] [ValidateInput(false)] public void LogFromJavaScript(String errorMessage) { log.Error("Log from JavaScript: " + errorMessage); } 

Java Script AJAX Implementation

 function LogFromJavaScript(errorMessage) { $.ajax( { url: window.urlLogError, type: "POST", dataType: "text", cache: false, data: { errorMessage: errorMessage } }); } 

And then use it in your JavaScript code

 window.LogFromJavaScript("Hello JS Log!"); 
0
source

Source: https://habr.com/ru/post/1383660/


All Articles