Introduction
This is the 5th article in a series on MVC logging.Our sample website now has Elmah, NLog, Log4Net and Health monitoring set up and working. Now it is time to start work on our log reporting website by tying them all together.
Preparing the database
ASP.NET Health Monitoring logs a lot of different types of messages but there is no way to differentiate whether a message is just for information purposes or whether it is an error message that may need attention. So to address this issue, let’s create a new table called “aspnet_WebEvent_ErrorCodes” and introduce a column called “Level” which will map each message eventcode to either “Info”, “Error”.The reason for doing this is so that we have a common “Level” attribute that we can use for all of our logging providers and this will allow us to later on filter all messages by their Log Level. Elmah for example will only be used to log unhandled exceptions so the LogLevel for our Elmah messages will always be “Error”.
Here is the database script necessary to add the new table to our database:
/****** Object: Table [dbo].[aspnet_WebEvent_ErrorCodes]
Script Date: 07/29/2010 09:56:45 ******/ IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[aspnet_WebEvent_ErrorCodes]')
AND type in (N'U')) DROP TABLE [dbo].[aspnet_WebEvent_ErrorCodes] GO /****** Object: Default [DF_aspnet_WebEvent_ErrorCodes_Level]
Script Date: 07/29/2010 09:56:45 ******/ IF EXISTS (SELECT * FROM sys.default_constraints
WHERE object_id = OBJECT_ID(N'[dbo].[DF_aspnet_WebEvent_ErrorCodes_Level]')
AND parent_object_id = OBJECT_ID(N'[dbo].[aspnet_WebEvent_ErrorCodes]')) Begin IF EXISTS (SELECT * FROM dbo.sysobjects
WHERE id = OBJECT_ID(N'[DF_aspnet_WebEvent_ErrorCodes_Level]') AND type = 'D') BEGIN ALTER TABLE [dbo].[aspnet_WebEvent_ErrorCodes]
DROP CONSTRAINT [DF_aspnet_WebEvent_ErrorCodes_Level] END End GO