Umbraco CMS(.NET):记录加载 xslt/用户控件的错误

发布于 2024-09-24 20:35:42 字数 102 浏览 0 评论 0原文

我想知道 Umbraco 是否有一种方法来记录无法加载 xslt 或用户控件时出现的错误。通常它会显示一个红色框,表示无法加载控件和内容。有没有办法正确记录这个?

提前致谢。

I was wondering if there's a way in Umbraco to log errors that we get when it fails to load xslt or user-controls. Generally it shows a red box saying it couldn't load the control and stuff. Is there a way to properly log this?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪若未夕 2024-10-01 20:35:42

首先,它并没有得到真正的支持...当发生错误时,它会输出 html 并写入 asp.net 跟踪日志。

这就是我将如何处理这个问题。我的大多数 Umbraco 安装使用 Elmah 进行异常日志记录,使用 log4net 进行应用程序日志记录。这应该会给你输出任何错误。

using System;
using System.Linq;
using System.Web;

public class MacroLogging : IHttpModule {

    public void Init(HttpApplication context) {
        context.LogRequest += ContextLogRequest;
    }

    static void ContextLogRequest(object source, EventArgs e) {
        var app = (HttpApplication)source;
        var context = app.Context;
        context.Trace.TraceFinished += TraceFinished;
    }

    static void TraceFinished(object sender, TraceContextEventArgs e) {
        var records = e.TraceRecords.Cast<TraceContextRecord>();
        var categoryTypes = new[] {"Macro", "macro", "umbracoMacro"};
        var traceOutput = records.Where(p => categoryTypes.Contains(p.Category) && p.IsWarning)));
        foreach (var entry in traceOutput) {
            //Your Output entry.Message
        }
    }

    public void Dispose() {}

}

只需将该模块添加到您的 web.config 中即可。我还没有测试过,因为现在是凌晨 1 点:),但总体概念应该可行。

First off, it's not really supported... When errors occur it outputs html and writes to the asp.net trace log.

Heres how I would approach this. Most of my Umbraco installations use Elmah for exception logging and log4net for application logging. This should give you any errors on output.

using System;
using System.Linq;
using System.Web;

public class MacroLogging : IHttpModule {

    public void Init(HttpApplication context) {
        context.LogRequest += ContextLogRequest;
    }

    static void ContextLogRequest(object source, EventArgs e) {
        var app = (HttpApplication)source;
        var context = app.Context;
        context.Trace.TraceFinished += TraceFinished;
    }

    static void TraceFinished(object sender, TraceContextEventArgs e) {
        var records = e.TraceRecords.Cast<TraceContextRecord>();
        var categoryTypes = new[] {"Macro", "macro", "umbracoMacro"};
        var traceOutput = records.Where(p => categoryTypes.Contains(p.Category) && p.IsWarning)));
        foreach (var entry in traceOutput) {
            //Your Output entry.Message
        }
    }

    public void Dispose() {}

}

Just add the module to your web.config. I have't tested as it's 1am :) but the overall concept should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文