3

I'm dealing with log files and calculating the traffic usage of each website. The default logging is missing my required fields (cs-host, sc-bytes, cs-bytes). While I'm able to change these configuration in Logging section of IIS which I can select the fields I want to include or exclude in my logging. I couldn't find any way to change these configuration for IIS Express. Is there anyway to define the fields I want to include in the log in IIS express?

Either using a GUI like the Logging in IIS configuration, Command line code, or just editing a configuration file?

IIS Log file configuration

I found the IIS Express logFile configuration but in there, but couldn't find anything about adding the fields there:

%userprofile%\documents\iisexpress\config\applicationhost.config

which has logFile configuration in SiteDefaults:

<siteDefaults>
    <logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs"/>
    <traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
</siteDefaults>
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
  • 1
    Does changing this setting as per [this](https://learn.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/sitedefaults/logfile/) help ? – Subbu Aug 16 '17 at 15:40
  • There is an IIS Express management console, https://www.jexusmanager.com/en/latest/ – Lex Li Aug 16 '17 at 19:12
  • 1
    @Subbu I actually have read this before but this time I read it more thoroughly and I found the solution. `logExtFileFlags` Attribute of the `logFile` is what I was looking for. Many thanks to you. – Ashkan Mobayen Khiabani Aug 16 '17 at 19:20
  • 1
    Great question. Thought I would add, you may find applicationhost.config in a hidden .vs folder under your solution.... Check out this [SO post](https://stackoverflow.com/questions/44174629/applicationhost-config-inside-hidden-vs-folder) – user2368632 Mar 18 '20 at 16:49

1 Answers1

3

To have a complete answer: you must first locate the applicationhost.config that corresponds to your site, and then edit the <logFile> section. It can either be defined in <siteDefaults> to apply the same settings to all sites, or it can be defined for each <site> section.

To configure the default categories, you can use the logExtFileFlags attribute:

The logExtFileFlags attribute can be one or more of the following values. If you specify more than one value, separate them with a comma (,).

In your case, you'll want Host, BytesRecv and BytesSent.

To add custom fields, you can use the <customFields> subsection.

Here's a complete example:

<logFile logFormat="W3C" directory="%AppData%\Microsoft\IISExpressLogs" 
 enabled="true" flushByEntryCountW3CLog="2" 
 logExtFileFlags="Host, BytesRecv, BytesSent">
  <customFields>
    <add logFieldName="custom-UUID" sourceType="RequestHeader" sourceName="UUID" />
  </customFields>
</logFile>
Métoule
  • 13,062
  • 2
  • 56
  • 84