最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

is there a log4net for javascript? - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a ment  | 

4 Answers 4

Reset to default 6

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

发布评论

评论列表(0)

  1. 暂无评论