Maybe start another thread about the best approach to Logs?
Um, this is another thread... :-)
On the logging front, Mike, at the top of every class I have this pure boilerplate (you can literally cut/paste between files)
#region Log4Net
static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
Then just sprinke the logging around. For example:
static public DateTime ConvertToDateTime(int numericDate)
{
log.DebugFormat("Converting '{0}' to a DateTime", numericDate);
try
{
if (numericDate != 0)
{
string strNumericDate = numericDate.ToString();
return new DateTime(Convert.ToInt32(strNumericDate.Substring(0, 4)),
Convert.ToInt32(strNumericDate.Substring(4, 2)),
Convert.ToInt32(strNumericDate.Substring(6, 2)));
}
else
{
return DateTime.MinValue;
}
}
catch (Exception ex)
{
log.Warn(String.Format("Error converting '{0}' to a date.", numericDate), ex);
return DateTime.MinValue;
}
}
What the output looks like all depends on how you configure the loggers, but here's a sample from my local dev box:
2012-08-06 17:38:45,114 INFO ASP.global_asax [(null)] - ----------------------
2012-08-06 17:38:45,265 INFO ASP.global_asax [(null)] - Application Starting... Good morning.
2012-08-06 17:38:45,268 INFO ASP.global_asax [(null)] - Watching 'c:\dev\IRBManager\Site\log4net.config'
2012-08-06 17:38:45,276 INFO ASP.global_asax [(null)] - Application Active.
2012-08-06 17:38:45,278 INFO ASP.global_asax [(null)] - --
2012-08-06 17:38:45,279 INFO ASP.global_asax [(null)] - Setting Aspose license from c:\dev\IRBManager\Site\Aspose.Words.lic
2012-08-06 17:38:45,812 INFO com.techsoftinc.PageLoadTimer [(null)] - Registering com.techsoftinc.PageLoadTimer HttpModule version 1.0.4444.29407.
2012-08-06 17:38:45,975 INFO com.techsoftinc.PageLoadTimer [(null)] - Registering com.techsoftinc.PageLoadTimer HttpModule version 1.0.4444.29407.
2012-08-06 17:38:46,986 INFO com.techsoftinc.PageLoadTimer [(null)] - Registering com.techsoftinc.PageLoadTimer HttpModule version 1.0.4444.29407.
2012-08-06 17:38:47,277 INFO com.techsoftinc.PageLoadTimer [(null)] - Registering com.techsoftinc.PageLoadTimer HttpModule version 1.0.4444.29407.
2012-08-06 17:38:47,810 INFO com.techsoftinc.PageLoadTimer [(null)] - Page /index.cfm processed in 522ms (/) (200 OK)
2012-08-06 17:38:47,906 INFO com.techsoftinc.PageLoadTimer [(null)] - Page / processed in 665ms (/) (200 OK)
2012-08-06 17:38:47,909 WARN com.techsoftinc.PageLoadTimer [(null)] - Page / processed in 1707ms (/) (200 OK)
2012-08-06 17:38:49,426 WARN com.techsoftinc.PageLoadTimer [C7853863-2BB0-44B1-97D1-B0470F3CCC8B] - Page /js/MergeAndReturn.ashx processed in 1457ms (/js/MergeAndReturn.ashx?s=/js/jQuery.tablesorter.modified.js;/js/tablesorter-widgets.js;/js/jQuery.metadata.js;/js/Placeholder.js;/js/jQuery.Query.2.1.7.js;/js/functions.js;/js/GoogleAnalytics.js) (200 OK)
2012-08-06 17:38:49,537 WARN com.techsoftinc.PageLoadTimer [127.0.0.1] - Page /public/GetLogo.ashx processed in 1568ms (/public/GetLogo.ashx?Client=dev) (200 OK)
2012-08-06 17:39:06,369 INFO ASP.global_asax [C7853863-2BB0-44B1-97D1-B0470F3CCC8B] - SessionStart for URL:
http://local.irbmanager.com/images/GetLogo.ashx
2012-08-06 17:39:06,375 INFO DBSessionHelper.DBSession [C7853863-2BB0-44B1-97D1-B0470F3CCC8B] - DBSession will use connection string: data source=db3;initial catalog=Session;User ID=Session;password=????;App=IRBManager
2012-08-06 17:39:06,569 INFO ASP.global_asax [C7853863-2BB0-44B1-97D1-B0470F3CCC8B] - Starting Session as user 101 (Admin) in client dev
2012-08-06 17:39:06,741 INFO com.techsoftinc.PageLoadTimer [C7853863-2BB0-44B1-97D1-B0470F3CCC8B] - Page /images/GetLogo.ashx processed in 486ms (/images/GetLogo.ashx) (200 OK)
2012-08-06 17:39:14,417 DEBUG com.techsoftinc.ViewStateInSQL.SQLPageStatePersister [C7853863-2BB0-44B1-97D1-B0470F3CCC8B dev] - Memory cache of 104857600 bytes will be used. Items will expire after 20 minutes.
2012-08-06 17:39:14,439 DEBUG com.techsoftinc.ViewStateInSQL.SQLPageStatePersister [C7853863-2BB0-44B1-97D1-B0470F3CCC8B dev] - Viewstate ba6aa443-a7e2-4c38-8401-fb82fc521ecc serialized to memory as 47996 bytes
2012-08-06 17:39:14,452 DEBUG com.techsoftinc.ViewStateInSQL.SQLPageStatePersister [C7853863-2BB0-44B1-97D1-B0470F3CCC8B dev] - Queuing write of viewstate ba6aa443-a7e2-4c38-8401-fb82fc521ecc to DB
2012-08-06 17:39:14,473 DEBUG com.techsoftinc.ViewStateInSQL.SQLPageStatePersister [(null)] - Writing viewstate ba6aa443-a7e2-4c38-8401-fb82fc521ecc to DB
2012-08-06 17:39:14,503 DEBUG com.techsoftinc.ViewStateInSQL.SQLPageStatePersister [(null)] - Done writing viewstate ba6aa443-a7e2-4c38-8401-fb82fc521ecc to DB
2012-08-06 17:39:14,567 WARN com.techsoftinc.PageLoadTimer [C7853863-2BB0-44B1-97D1-B0470F3CCC8B] - Page /xForms/admin/FormList.aspx processed in 4248ms (/xForms/admin/FormList.aspx) (200 OK)
-Walden
As an Amazon Associate we earn from qualifying purchases.