对于 SharePoint 2013,有没有办法使用 JSOM 登录到 ULS?
如果可能的话,我想避免编写可以使用 ajax 调用的自定义处理程序之类的事情。
最佳答案
SharePoint 提供了名为 SharePoint Diagnostics (diagnostics.asmx
) 的 Web 服务,此 Web 服务使客户端应用程序能够将诊断报告直接提交到 ULS 日志,请按照 Writing to the SharePoint Unified Logging Service from JavaScript了解更多详情。
SharePoint JavaScript 库 (init.js
) 包含使用诊断 Web 服务的以下函数:
function ULSOnError(msg, url, line) {
return ULSSendExceptionImpl(msg, url, line, ULSOnError.caller);
}
function ULSSendException(ex) {
var message = ex.message;
if (typeof message == "undefined")
message = ex.toString();
ULSSendExceptionImpl(message, location.href, 0, ULSSendException.caller);
}
示例
var ctx = SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle(listTitle);
ctx.load(list);
ctx.executeQueryAsync(function() {
//...
},
function(sender,args){
ULS.enable = true; //ensure ULS logging is enabled
ULSOnError('An error occured while getting list' + args.get_message(), location.href, 0);
});
关于javascript - 使用 JSOM 将错误记录到 ULS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32254661/