For IIS 7 - 8:
Follow the directions here.
For IIS 8.5 - 10:
From IIS 8.5 onwards, custom logging is a built-in option. See IIS Enhanced Logging.
1. In IIS Manager, double click on 'Logging' in the actions menu of the site you are working on.
2. After this launches, select W3C as the format and then click Select Fields next to the format drop-down in the Log File sub-section.
3. Click on 'Add Field' and add as per below
4. Click OK. You should see your new entry reflected under 'Custom Fields'. Click on Apply when you are back in the 'Logging' window.
- If this is successful, the log file should now have an underscore like so:
You should also see the change in the fields:
Restart the site, then W3SVC, then the entire instance if the change doesn’t reflect immediately.
Note: When using enhanced logging in IIS 8.5+, it does not restore original visitor IP at the application level.