87
We will use this code to generate some log files and explore the types of logs available. The types of
logs that can be enabled for a web app are as follows:
Application logging These are logs that are written specifically from your application code
using diagnostic classes such as the System.Diagnostics.Trace or the System.Diagnostics.Debug.
The latter only works if you publish a debug build of your web app (something you should
never do on a production app). When you enable application logging, you also must specify a
log level, which can be , , , or . Each log level includes the
previous level. For example, if you want only error logs, then you would set the logging level to
Error. If you want only error and warning logs, then you would set the logging level to Warning,
and so on.
Web server logging These are HTTP logs (that is, IIS logs) that are written by the web server
on which your web app is running. Data in these logs contains fields defined in the W3C
extended log file format defined at
https://msdn.microsoft.com/library/windows/desktop/aa814385.aspx and includes things such
as the time it took the server to process a request, cookies that were sent to the client or
received by the client, the client’s IP address, and much more.
Detailed error messages These are HTML files written by the web server for any requests to
the server that result in an HTTP status code 400 or above response. For example, if you request
a resource that doesn’t exist on the server, you will get an HTTP 404 (Not Found) response.
With detailed error messages enabled, an HTML file also will be generated containing
suggested causes, possible solutions, and additional details about the request.
Failed request tracing These are XML files written by the web server containing a deeper level
of trace information for failed requests. These logs contain visibility into the HTTP modules that
were invoked when processing the request, time taken in each module, module tracing
messages, and more. A new XML file is generated for each failed request and is named
where <x> is an incrementing number. Failed request logs are intended to be
viewed using a browser, and Azure Web Apps facilitates this by generating a style sheet file
named in the directory where these files are stored.
Tip The Verbose log-level in application logging will include logs written using the
System.Diagnostics.Debug class only if you publish a debug build of your web app. For example, if you
use Debug.WriteLine() as a debugging aid in your code, then setting the log level to Verbose will
enable you to see these logs when your web app is running in Azure. This behavior does not apply to
release builds of your web app.
Debug logging is intended primarily for local development and debugging, so you shouldn’t deploy
debug builds to Azure unless it is in a Dev/Test environment and you are troubleshooting an issue that
requires additional debug logging.