在ASP.NET MVC应用程序中定义异常处理和错误日志记录的最佳实践?(Best practice for where to define exception handling and error

编程入门 行业动态 更新时间:2024-10-22 23:10:31
在ASP.NET MVC应用程序中定义异常处理和错误日志记录的最佳实践?(Best practice for where to define exception handling and error logging in ASP.NET MVC applications?)

在典型的MVC应用程序中,您有许多层。

数据库层模型层(可能与数据库在同一个包中)视图/ UI层控制器层业务层

如果要在足够复杂的MVC应用程序中创建错误日志记录的自定义异常,接口和模型,那么异常处理或错误日志记录应该放在何处?

In your typical MVC application, you have many layers.

Database layer Model layer (possibly in the same package as the DB) View/UI Layer Controller Layer Business Layer

Where should the exception handling or error logging live here, if you were to create custom exceptions, interfaces and models for error logging in a sufficiently complex MVC application?

最满意答案

您应该在数据层中处理来自数据层的异常(例如,SQLExceptions),控制器中的异常,控制器/逻辑异常以及显示相关异常的视图。 使用像ELMAH这样的日志记录解决方案来记录异常并捕获未处理的异常。

You should handle exceptions in your data layer that come from your data layer (SQLExceptions, for example), in your controller for controller/logic exceptions, and in your view for display related exceptions. Use a logging solution like ELMAH to log exceptions and catch unhandled exceptions.

更多推荐

本文发布于:2023-08-02 19:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379653.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   异常   定义   错误   日志

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!