HttpModule错误事件未触发

时间:2016-07-08 08:11:47

标签: asp.net asp.net-web-api httpmodule ihttpmodule

我有一个Asp.Net Web Api项目,我正在尝试为记录错误创建一个简单的runAllManagedModulesForAllRequests="true"

模块正确加载,因为我可以注册到BeginRequest / EndRequest事件。但是,永远不会触发Error事件。

我还在web.config添加并删除了public class ErrorLogModule : IHttpModule { public void Init(HttpApplication context) { context.Error += Context_Error; } // method never triggered private void Context_Error(object sender, EventArgs e) { HttpContext ctx = HttpContext.Current; Exception exception = ctx.Server.GetLastError(); // todo // log Exception } public void Dispose() { } } <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="ErrorLogger" type="HttpModules.HttpModules.ErrorLogModule" /> </modules> </system.webServer> [HttpGet] [Route("triggerError")] public string TriggerError() { int test = 0; var a = 1 / test; return "Hello Workd"; } 属性,但仍然无效。

Observable.combineLatest(
        RxView.touches(vSecretLeft)
                .filter(motionEvent -> motionEvent.getAction() == MotionEvent.ACTION_DOWN || motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL),
        RxView.touches(vSecretRight)
                .filter(motionEvent -> motionEvent.getAction() == MotionEvent.ACTION_DOWN || motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL),
        RxTextView.textChanges(etxtSearchFilter)
                .debounce(1, TimeUnit.SECONDS)
                .map(c -> c.toString().trim())
                .filter(s -> !s.isEmpty()),
        (motionEventLeft, motionEventRight, entered) -> {
            boolean overrideFilter = motionEventLeft.getAction() == MotionEvent.ACTION_DOWN && motionEventRight.getAction() == MotionEvent.ACTION_DOWN;
            return overrideFilter || !isInappropriate(entered) ? entered : "BLOCKED";
        })
        .subscribe(s -> Log.i("ObservableCombineLatest", "s: " + s));

1 个答案:

答案 0 :(得分:0)

您可以使用更好的日志记录方法,即100%可用。 参见this Microsoft article

简而言之,您可以实施

YourExceptionLogger: ExceptionLogger

只有一种覆盖方法,并通过

注册
config.Services.Add(typeof(IExceptionLogger), new YourExceptionLogger());