现在Silverlight 2终于发布了。我想知道是否有人为它组合了一些日志记录框架,比如enterprise library logging或log4net?我感兴趣的是可以执行客户端跟踪并将消息记录到服务器的东西。
到目前为止,我找到的唯一一个项目是CodeProject上的Clog。有人用过这个吗?你对此有什么想法?
发布于 2009-05-25 06:40:21
如果您只想将调试消息输出到控制台。您可以使用浏览器的console.log机制。我为此编写了一个扩展方法。你可以在my blog上找到。
// http://kodierer.blogspot.com.es/2009/05/silverlight-logging-extension-method.html
public static string Log(string message)
{
var msgLog = "";
try
{
HtmlWindow window = HtmlPage.Window;
//only log if a console is available
var isConsoleAvailable = (bool)window.Eval("typeof(console) != 'undefined' && typeof(console.log) != 'undefined'");
if (!isConsoleAvailable) return "isConsoleAvailable " + isConsoleAvailable;
var createLogFunction = (bool)window.Eval("typeof(ssplog) == 'undefined'");
if (createLogFunction)
{
// Load the logging function into global scope:
string logFunction = @"function ssplog(msg) { console.log(msg); }";
string code = string.Format(@"if(window.execScript) {{ window.execScript('{0}'); }} else {{ eval.call(null, '{0}'); }}", logFunction);
window.Eval(code);
}
// Prepare the message
DateTime dateTime = DateTime.Now;
string output = string.Format("{0} - {1} - {2}", dateTime.ToString("u"), "DEBUG", message);
// Invoke the logging function:
var logger = window.Eval("ssplog") as ScriptObject;
logger.InvokeSelf(output);
}
catch (Exception ex)
{
msgLog = "Error Log " + ex.Message;
}
return msgLog;
}https://stackoverflow.com/questions/228723
复制相似问题