The docs show how to set a page for when an exception occurs: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling
But how do I record the details of the exception in a log file on my server?
Does kestrel log exceptions and errors anywhere by default or do I have to do this manually?
Are there any examples or documentation available?
Yes, ASP.NET core has the built-in logging, but it does not provide the ability to log to file directly. Instead, you need to use 3-rd party libraries. The good news is that all three most common logging libraries are available already for .NET Core as nuget packages: NLog, Serilog and log4net.
This article has a good overview over them and provides how-to-use examples: ASP.NET Core Logging Tutorial – What Still Works and What Changed?.
Then I suggest looking into samples in aspnet/Diagnostics repo. It shows how to custom or built-in error Middleware, ExceptionHandler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With