I have the following exception:
public class InvalidStatusCodeException : Exception
{
public HttpStatusCode ReceivedStatusCode { get; set; }
public string ApiUrl { get; set; }
public InvalidStatusCodeException(HttpStatusCode receivedStatusCode, string apiUrl)
{
ReceivedStatusCode = receivedStatusCode;
ApiUrl = apiUrl;
}
}
throw it in some cases:
string url = "api/group/1/getAll";
var response = await _client.GetAsync(url);
if (!response.IsSuccessStatusCode)
throw new InvalidStatusCodeException(response.StatusCode, url);
if I catch and log this exception:
catch(InvalidStatusCodeException status_ex)
{
string error = $"Invalid Status code for request: '{status_ex.ApiUrl}', received code: {status_ex.ReceivedStatusCode}";
log.LogError(status_ex, error, "InvalidStatusCode");
}
I don't see values of my custom properties (ReceivedStatusCode, ApiUrl) and can see details only in error message.
If I don't catch this exception at all and exception is being logged automatically then no way to see details at all.
Any way to see these custom properties without additional catching of exception?