mardi 6 mars 2007

GetCurrentProcessInfo() and IIS6

Process metrics are available only when the ASP.NET process model is enabled. When running on versions of IIS 6 or newer in worker process isolation mode, this feature is not supported.
at System.Web.ProcessModelInfo.GetCurrentProcessInfo()
at ...

Nice feature.

Every web application we have use the same logging technique :
ProcessInfo piUser = ProcessModelInfo.GetCurrentProcessInfo();
swLogFile.WriteLine("{0} - Process ID {1} started at {2} - Memory peak : {3}", dtNow.ToLongTimeString(), piUser.ProcessID, piUser.StartTime, piUser.PeakMemoryUsed);
swLogFile.WriteLine("{0} - Status : {1}", dtNow.ToLongTimeString(), piUser.Status);
swLogFile.WriteLine("{0} - Shutdown Reason : {1}", dtNow.ToLongTimeString(), piUser.ShutdownReason);
swLogFile.WriteLine("{0} - Method : {1}", dtNow.ToLongTimeString(), ProcedureName);
swLogFile.WriteLine("{0} - Message : {1}", dtNow.ToLongTimeString(), e.Message);
swLogFile.WriteLine("{0} - Detailled error file : {1}", dtNow.ToLongTimeString(), WriteErrorLog(e));


On all our W2k web servers, this works well.
On all the WXP dev stations this works well.
On the new W2k3 web server, this fails miserably.

So we just have to change it to this :

try
{ piUser = ProcessModelInfo.GetCurrentProcessInfo(); }
catch
{//We're not running under ASP.NET process model.
piUser = null;
}


And make sure that the Append to StreamWriter doesn't want to access
piUser.ProcessID

Aucun commentaire: