For IIS 7:
Follow the directions here.
For IIS 8:
Note: From IIS 8.5 onwards, custom logging is available built-in as Enhanced Logging
1.) If you haven't already, install Advanced Logging for IIS.
2.) In IIS Manager, go to the zone you are working with and go into Advanced Logging
3.) Enable Advanced Logging on the right column labeled "Actions"
4.) Also, under "Actions" click "Edit Logging Fields"
5.) Enter in this information:
Field ID: CF-Connecting-IP
Source Type: Request Header
Source Name: CF-Connecting-IP
6.) Press OK.
7.) Back in "Advanced Logging," double click the Log Definition that you want to work with.
8.) Under "Selected Fields" click "Select Fields"
9.) Check the box for "CF-Connecting-IP"
10.) Press OK
11.) Click Apply under "Actions" on the right side.
12.) Go back to the server's "Home" and restart the server.
Note: When using enhanced logging in IIS 8+, it does not restore original visitor IP at the application level.