Umbraco CMS(.NET): Logging errors loading xslt/User controls

。_饼干妹妹 提交于 2019-12-12 08:53:55

问题


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.


回答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.



来源:https://stackoverflow.com/questions/3809618/umbraco-cms-net-logging-errors-loading-xslt-user-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!