Rodniko
Rodniko

Reputation: 5124

is there a log4net for javascript?

i want to log an asp.net , 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?

Upvotes: 4

Views: 5463

Answers (4)

webMac
webMac

Reputation: 203

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!");

Upvotes: 1

Dave Newton
Dave Newton

Reputation: 160191

There are several options.

I liked lumberjack, but can't locate it at the moment.

Upvotes: 6

Graham Clark
Graham Clark

Reputation: 12966

There's a log4javascript, which is based on log4j (as is log4net).

Upvotes: 6

Darthg8r
Darthg8r

Reputation: 12675

I simply use Console.log. It logs data to the firefox/chrome console.

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

Upvotes: 1

Related Questions