Best practice for logging the http request in an HTTP triggered Azure Function #175
Unanswered
pim-simons
asked this question in
Q&A
Replies: 1 comment
-
There's indeed no (built-in) middleware to catch this, so you should do it yourself. There's is though an overload where you can pass along the response HTTP status code instead of the actual response where you set the status code manually. _logger.LogRequest(req.HttpContext.Request, 500, stopWatch.Elapsed); I guess it's dependent on the situation. Adding @tomkerkhove to this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In an HTTP triggered Azure Function I want to log the http request, I also use a try catch containing the actual logic of the Azure Function.
My code looks like this (removed the parts that are not relevant):
As you can see I log the request in the finally statement to make sure the request is logged even when an error occurs.
I manually set the HttpContext.Response.StatusCode to 500 to indicate an error.
I am just wondering if this is the right way to go, is there a better way to update the HttpContext.Response.StatusCode instead of manually assigning it?
Beta Was this translation helpful? Give feedback.
All reactions