Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added exception middleware to server for logging #3925

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

pyramidsbuilder
Copy link
Contributor

added exception middlware to log server exceptions

@sbwalker
Copy link
Member

sbwalker commented Mar 1, 2024

Oqtane already has database logging for all scenarios where a tenant can be identified... and file logging for scenarios where it cannot. This PR adds more logging on top of the existing logging - which does not make sense?

@pyramidsbuilder
Copy link
Contributor Author

pyramidsbuilder commented Mar 1, 2024

@sbwalker Oqtane has logging which I used in the middleware,
In my case I was writing module and when the module throws an exception, it is not logged.
unless the module try/catch exceptions on the "methods" level and loggs it, you cannot get information about the error happened.
The middleware handles any exception happens on server app including modules exceptions and log it.
On client side it is already there, it uses OnError and catch/log client exceptions by default, but on server side it is missing this feature

@sbwalker
Copy link
Member

sbwalker commented Mar 1, 2024

Unhandled exceptions in module components are supposed to be caught by the ErrorBoundary which is in Oqtane.Client\UI\RenderModeBoundary.razor. The ErrorBoundary logs the detailed error and displays a friendly error message to the UI. So I am curious why your module components would not function properly. Are the module components specifying public override string RenderMode => RenderModes.Static... or are they Interactive (default)?

@pyramidsbuilder
Copy link
Contributor Author

@sbwalker I have the client error logging working but it is not a detailed messages it looks like this
Request /api/EndPoint?moduleid=1&authmoduleid=1 Failed With Status 500 - Internal Server Error

while I need the actual error stack trace and line number which the exception middleware can provide, for example:

System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Guid'.
   at Microsoft.Data.SqlClient.SqlBuffer.get_Guid()
***************************
*********************************************\Server\Repository\Repository.cs:line 23
   
****************************Server\Controllers\Controller.cs:line 57

@sbwalker
Copy link
Member

sbwalker commented Mar 1, 2024

Oh ok... so this is intended for server-side logging of unhandled exceptions. Did you look in the Oqtane.Server\Content\Log\error.log file to determine if these errors were logged there? This error log is also displayed in the UI when you go to Admin Dashboard / System Info and choose the Log tab.

@pyramidsbuilder
Copy link
Contributor Author

@sbwalker yes it is logged there, thanks for details, it is not necessary then

@sbwalker
Copy link
Member

sbwalker commented Mar 1, 2024

@pyramidsbuilder I actually think there is value in this PR, as in those scenarios where the tenant can be determined, it can log the exception to the appropriate database (tenant) for the correct site. This keeps the exceptions grouped together and much easier to locate. And in the cases where the tenant cannot be determined, it can fallback to use the file logger.

@sbwalker sbwalker merged commit 62695d4 into oqtane:dev Mar 1, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants