We have IIS 8.5 hosted REST based Web API services. The default logging is W3C format. Client can cancel the ongoing request and these are logged with the status code of 500.
When request header logging is turned on to capture a request header in IIS log, a custom header used in the application: Logging -> Log File Format -> Select Fields -> Custom Fields -> Add Field Field Name: XView Source Type: Request Header Source: XView (custom request header)
After this change, the IIS log response code logged is 0 instead of 500 when client cancels the operation.
Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken 2019-03-28 08:30:24 10.91.1.183 GET /api/MyTestUri filter=SampleNumber:-2&itemsPerPage=25&pageNumber=1 65435 UserId 10.91.2.14 - - 500 0 64 0 943 6968 Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken XView 2019-03-28 09:33:26 10.91.1.183 GET /api/MyTestUri filter=SampleNumber:-2&itemsPerPage=25&pageNumber=1 65435 UserId 10.91.2.14 - - 0 0 64 0 943 6874 -
The event log continues to have an Exception type: OperationCanceledException as earlier and Failed Request Trace in IIS shows the response code as 500 (final status).
Other threads have discussed when status 0 can occur, e.g. https://stackoverflow.com/q/3825581/987191 but not this specific scenario.
We need custom headers to be logged to add more context to the IIS log, but would like it to continue to log 500 status, so that we can isolate other failures such as failures during heavy load log 0 status in response. This change in behavior due to request header logging is adding noise in the logs. I could not find enough documentation on why response code changes, but if anyone has any information, that will be appreciated.