Verbose ASP.NET website Hosting Environment Logging

How to get verbose information about current ASP.NET website hosting environment? It is very actual when we host a website on a shared hosting server.

Often, some features are working on our dev machine doesn't work on a remote server. For instance, it can be Excel importing, ODBC data access and others features. Errors could be due to server feature restrictions or memory limit.

So, how to get verbose asp.net website hosting environment information to understand what is wrong with our asp.net website? Most asp.net development guides tells that web.config can show exceptions (setting in <customErrors /> section) and a developer can handle them in the Application_Error handler. Yes, it is correct way to log errors. For error logging we prefer NLog as easy-to-configure logging solution.

In asp.net, there are 3 classes that provides additional verbose information: System.Environment, System.Web.Hosting.HostingEnvironment, SysteM.Web.HttpRuntime. All classes have static properties with some useful info. So, to log all info we add logging lines into Application_Start event handler like below:

logger.Info("HostingEnvironment.ApplicationID: {0}", HostingEnvironment.ApplicationID); logger.Info("HostingEnvironment.ApplicationPhysicalPath: {0}", HostingEnvironment.ApplicationPhysicalPath); logger.Info("HostingEnvironment.ApplicationVirtualPath: {0}", HostingEnvironment.ApplicationVirtualPath); logger.Info("HostingEnvironment.InClientBuildManager: {0}", HostingEnvironment.InClientBuildManager); logger.Info("HostingEnvironment.IsDevelopmentEnvironment: {0}", HostingEnvironment.IsDevelopmentEnvironment); logger.Info("HostingEnvironment.IsHosted: {0}", HostingEnvironment.IsHosted); logger.Info("HostingEnvironment.MaxConcurrentRequestsPerCPU: {0}", HostingEnvironment.MaxConcurrentRequestsPerCPU); logger.Info("HostingEnvironment.MaxConcurrentThreadsPerCPU: {0}", HostingEnvironment.MaxConcurrentThreadsPerCPU); logger.Info("HostingEnvironment.SiteName: {0}", HostingEnvironment.SiteName); logger.Info("Environment.Is64BitOperatingSystem: {0}", Environment.Is64BitOperatingSystem); logger.Info("Environment.Is64BitProcess: {0}", Environment.Is64BitProcess); logger.Info("Environment.MachineName: {0}", Environment.MachineName); logger.Info("Environment.OSVersion: {0}", Environment.OSVersion); logger.Info("Environment.ProcessorCount: {0}", Environment.ProcessorCount); logger.Info("Environment.SystemPageSize: {0}", Environment.SystemPageSize); logger.Info("Environment.WorkingSet: {0}", Environment.WorkingSet); logger.Info("Environment.Version: {0}", Environment.Version); logger.Info("Environment.UserName: {0}", Environment.UserName); logger.Info("Environment.UserInteractive: {0}", Environment.UserInteractive); logger.Info("Environment.TickCount: {0}", Environment.TickCount); logger.Info("Environment.SystemDirectory: {0}", Environment.SystemDirectory); logger.Info("Environment.CurrentDirectory: {0}", Environment.CurrentDirectory); logger.Info("Environment.CommandLine: {0}", Environment.CommandLine); logger.Info("HttpRuntime.AppDomainAppId: {0}", System.Web.HttpRuntime.AppDomainAppId); logger.Info("HttpRuntime.AppDomainAppPath: {0}", System.Web.HttpRuntime.AppDomainAppPath); logger.Info("HttpRuntime.AppDomainAppVirtualPath: {0}", System.Web.HttpRuntime.AppDomainAppVirtualPath); logger.Info("HttpRuntime.AppDomainId: {0}", System.Web.HttpRuntime.AppDomainId); logger.Info("HttpRuntime.AspClientScriptPhysicalPath: {0}", System.Web.HttpRuntime.AspClientScriptPhysicalPath); logger.Info("HttpRuntime.AspInstallDirectory: {0}", System.Web.HttpRuntime.AspInstallDirectory); logger.Info("HttpRuntime.BinDirectory: {0}", System.Web.HttpRuntime.BinDirectory); logger.Info("HttpRuntime.ClrInstallDirectory: {0}", System.Web.HttpRuntime.ClrInstallDirectory); logger.Info("HttpRuntime.CodegenDir: {0}", System.Web.HttpRuntime.CodegenDir); logger.Info("HttpRuntime.IISVersion: {0}", System.Web.HttpRuntime.IISVersion); logger.Info("HttpRuntime.IsOnUNCShare: {0}", System.Web.HttpRuntime.IsOnUNCShare); logger.Info("HttpRuntime.MachineConfigurationDirectory: {0}", System.Web.HttpRuntime.MachineConfigurationDirectory); logger.Info("HttpRuntime.TargetFramework: {0}", System.Web.HttpRuntime.TargetFramework); logger.Info("HttpRuntime.UsingIntegratedPipeline: {0}", System.Web.HttpRuntime.UsingIntegratedPipeline); logger.Info("HttpRuntime.Cache.EffectivePercentagePhysicalMemoryLimit: {0}", System.Web.HttpRuntime.Cache.EffectivePercentagePhysicalMemoryLimit); logger.Info("HttpRuntime.Cache.EffectivePrivateBytesLimit: {0}", System.Web.HttpRuntime.Cache.EffectivePrivateBytesLimit);

So we can see which bitness of the current CPU. Which bitness of the current process and how much memory hoster allocates to our website. For instance, we get the next log lines for the our website:

 

2016-09-29 01:20:35.4275 INFO Application_Start ********************************************************************* 2016-09-29 01:20:35.5525 INFO HostingEnvironment.ApplicationID: /LM/W3SVC/2358/ROOT 2016-09-29 01:20:35.5525 INFO HostingEnvironment.ApplicationPhysicalPath: E:\HostingSpaces\******\******.***\wwwroot\ 2016-09-29 01:20:35.5525 INFO HostingEnvironment.ApplicationVirtualPath: / 2016-09-29 01:20:35.5525 INFO HostingEnvironment.InClientBuildManager: False 2016-09-29 01:20:35.5525 INFO HostingEnvironment.IsDevelopmentEnvironment: False 2016-09-29 01:20:35.5525 INFO HostingEnvironment.IsHosted: True 2016-09-29 01:20:35.5525 INFO HostingEnvironment.MaxConcurrentRequestsPerCPU: 5000 2016-09-29 01:20:35.5525 INFO HostingEnvironment.MaxConcurrentThreadsPerCPU: 0 2016-09-29 01:20:35.5525 INFO HostingEnvironment.SiteName: ******.*** 2016-09-29 01:20:35.5525 INFO Environment.Is64BitOperatingSystem: True 2016-09-29 01:20:35.5525 INFO Environment.Is64BitProcess: False 2016-09-29 01:20:35.5525 INFO Environment.MachineName: C****S 2016-09-29 01:20:35.5525 INFO Environment.OSVersion: Microsoft Windows NT 6.2.9200.0 2016-09-29 01:20:35.5525 INFO Environment.ProcessorCount: 24 2016-09-29 01:20:35.5525 INFO Environment.SystemPageSize: 4096 2016-09-29 01:20:35.5525 INFO Environment.WorkingSet: 56438784 2016-09-29 01:20:35.5525 INFO Environment.Version: 4.0.30319.42000 2016-09-29 01:20:35.5525 INFO Environment.UserName: pnsolscom_web 2016-09-29 01:20:35.5681 INFO Environment.UserInteractive: False 2016-09-29 01:20:35.5681 INFO Environment.TickCount: 114640 2016-09-29 01:20:35.5681 INFO Environment.SystemDirectory: C:\Windows\system32 2016-09-29 01:20:35.5681 INFO Environment.CurrentDirectory: C:\Windows\SysWOW64\inetsrv 2016-09-29 01:20:35.5681 INFO Environment.CommandLine: C:\Windows\SysWOW64\inetsrv\w3wp.exe -ap "******.*** v4.0 (Integrated)" -v "v4.0" -l "webengine4.dll" -a \\.\pipe\iisipm1769415e-8416-4440-bc9c-953abe5102a3 -h "C:\inetpub\temp\apppools\******.*** v4.0 (Integrated)\******.*** v4.0 (Integrated).config" -w "" -m 0 -t 20 2016-09-29 01:20:35.5681 INFO HttpRuntime.AppDomainAppId: /LM/W3SVC/2358/ROOT 2016-09-29 01:20:35.5681 INFO HttpRuntime.AppDomainAppPath: E:\HostingSpaces\******\******.***\wwwroot\ 2016-09-29 01:20:35.5681 INFO HttpRuntime.AppDomainAppVirtualPath: / 2016-09-29 01:20:35.5681 INFO HttpRuntime.AppDomainId: /LM/W3SVC/2358/ROOT-1-131196035382806747 2016-09-29 01:20:35.5681 INFO HttpRuntime.AspClientScriptPhysicalPath: C:\Windows\Microsoft.NET\Framework\v4.0.30319\asp.netclientfiles 2016-09-29 01:20:35.5681 INFO HttpRuntime.AspInstallDirectory: C:\Windows\Microsoft.NET\Framework\v4.0.30319\ 2016-09-29 01:20:35.5681 INFO HttpRuntime.BinDirectory: E:\HostingSpaces\******\******.***\wwwroot\bin\ 2016-09-29 01:20:35.5681 INFO HttpRuntime.ClrInstallDirectory: C:\Windows\Microsoft.NET\Framework\v4.0.30319\ 2016-09-29 01:20:35.5681 INFO HttpRuntime.CodegenDir: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\423a886b\ea71435d 2016-09-29 01:20:35.5681 INFO HttpRuntime.IISVersion: 8.0 2016-09-29 01:20:35.5681 INFO HttpRuntime.IsOnUNCShare: False 2016-09-29 01:20:35.5681 INFO HttpRuntime.MachineConfigurationDirectory: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config 2016-09-29 01:20:35.5681 INFO HttpRuntime.TargetFramework: 4.5 2016-09-29 01:20:35.5681 INFO HttpRuntime.UsingIntegratedPipeline: True 2016-09-29 01:20:35.5681 INFO HttpRuntime.Cache.EffectivePercentagePhysicalMemoryLimit: 99 2016-09-29 01:20:35.5681 INFO HttpRuntime.Cache.EffectivePrivateBytesLimit: 62914560

 

As you can see there are many useful lines to understand which server configuration at the moment for our website. At this point it is enough for this topic. Have a nice asp.net websites and servers to host them.

asp.net, asp.net hosting, asp.net hosting environment, asp.net logging