i want to log an asp , framework 4.0 web application. i'm using log4net as my logging device and the RollingFileAppender is working great from the code behind.
can log4net log javascript ? if yes , how? if not, how do you guys log a javascript?
i want to log an asp , framework 4.0 web application. i'm using log4net as my logging device and the RollingFileAppender is working great from the code behind.
can log4net log javascript ? if yes , how? if not, how do you guys log a javascript?
Share Improve this question asked Nov 29, 2011 at 14:58 RodnikoRodniko 5,12422 gold badges73 silver badges93 bronze badges4 Answers
Reset to default 6There's a log4javascript, which is based on log4j (as is log4net).
There are several options.
- log4javascript
- log4js
- blackbirdjs (current favorite)
I liked lumberjack, but can't locate it at the moment.
I simply use Console.log. It logs data to the firefox/chrome console.
http://getfirebug./wiki/index.php/Console_API#console.log.28object.5B.2C_object.2C_....5D.29
Alternatively you can just implement a REST POST Function in an .Net Controller an call it via AJAX in your JavaScript Code.
Example given:
.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!");