Place of registration

Where should I log exceptions? At the data service layer (ExecuteDataSet, etc.) and / or at the data access and / or business layer?

+1


source to share


3 answers


At the edge of the physical layer.

Also in the top-level exception handler on the client.



those. if your business layer is running on a server, log exceptions before propagating to the client. It's easy if you publish your business layer as WCF Web Services, you can implement an error handler that does the registration before propagating the SOAP error to the client.

+2


source


If you throw an exception, you should log it when it does, and then bubble it up. Otherwise, only the end user should log the exception (you can have a lot of traceback, of course, in which case it can be logged quite a bit).

The end user can be a UI component or service or whatever ...



If you are handling the exception somewhere, then this is the end user and you should register it. In most applications, and in most cases, it should be logged by the user interface when it displays an error message to the user.

+1


source


I usually allow exceptions to propagate and be logged when they reach the topmost level. for example

main {
    try {
        application code
    } catch {
        preform logging
    }
}

      

But this only makes sense for fatal exceptions. Other exceptions I usually log them in the block that handles the recovery from the specified exception.

+1


source







All Articles