Correct way to log exception in interceptor?
See original GitHub issueHey all. How should a catch-all exception logger look like? The code below does what I want, but I’m not sure if returning null
is the best idea. I’ve checked the sample here, but there is no exception handling https://github.com/grpc/grpc-dotnet/blob/1f67ee2d00e60281dfc78a072b41fc575e0d1ce3/examples/Logger/Server/ServerLoggerInterceptor.cs.
I’m using .NET Framework and including gRPC and Microsoft.Extensions.Hosting packages so I don’t get the nice stuff that .NET Core has by default. Thanks!
public override Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, ServerCallContext context, UnaryServerMethod<TRequest, TResponse> continuation)
{
try
{
return base.UnaryServerHandler(request, context, continuation);
}
catch (Exception exception)
{
_logger.LogError(exception.ToString());
return null;
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Log4j Logger for Struts 2 Exception Interceptor - java
To enable logging of the exceptions being handled by the Struts 2 framework you must specify some parameter values in struts.xml.
Read more >Get Exception Details Inside Mule Interceptor
I was thinking is there any way to get the exception details inside this method by using may be MuleEvent object. Or is...
Read more >Logging and intercepting database operations - EF6
Starting with Entity Framework 6, anytime Entity Framework sends a command to the database this command can be intercepted by application ...
Read more >Logging Exceptions in Java - Loggly
A look at common approaches to exception handling and logging in Java. ... Choosing one option over the other depends mostly on how...
Read more >Class ExceptionMappingInterceptor
This interceptor forms the core functionality of the exception handling feature. Exception handling allows you to map an exception to a result code, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Adding async/await do the trick
@thdotnet yup. If you are using .net core, it is as simple as
If you are using .net framework, it is a bit more involved