Click here to Skip to main content
15,893,588 members
Articles / Web Development / ASP.NET

Designing and implementing a versatile data access tier for an ASP.NET application

Rate me:
Please Sign up or sign in to vote.
4.63/5 (45 votes)
3 Feb 200328 min read 384.8K   3.8K   242  
In this article, we will drill down deeper in to the design of a n-tier architecture and our focus will be on the data access tier (DAT)
using System;
using System.Diagnostics;

namespace ELCreator
{
	/// <summary>
	/// This class create an event log and a source to DATier, BATier
	/// and Presentation Tier
	/// </summary>
	class Creator
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{

			// Initialize the names for the logs and their sources 
			string strMachine = "abraham";//change the machine name
			string strLogBL = "BLLog";
			string strLogDA = "DALog";
			string strLogPL = "PLLog";
			string strSourceBL = "BLSource";
			string strSourceDA = "DASource";
			string strSourcePL = "PLSource";
			

			try
			{
				// Create EventLog for Business Logic 
				if(!EventLog.SourceExists(strSourceBL,strMachine))
				{
					EventLog.CreateEventSource(strSourceBL,strLogBL,strMachine);
					Console.WriteLine("New log and a source for BL is  created");
					
				}
				else
				{
                    Console.WriteLine(" source for BL exists already");
					 //EventLog.Delete(strLogBL,strMachine);
				}
			
				// create an instance of EventLog of BL and enter some test entries
				EventLog elBL= new EventLog(strLogBL,strMachine,strSourceBL);
				elBL.WriteEntry("Test Error",EventLogEntryType.Error);
				elBL.WriteEntry("Test Inforamtion",EventLogEntryType.Information);
                elBL.WriteEntry("Test Warning",EventLogEntryType.Warning);

				// Create EventLog for Data Access Tier
				if(!EventLog.SourceExists(strSourceDA,strMachine))
				{
					
					EventLog.CreateEventSource(strSourceDA,strLogDA,strMachine);
					Console.WriteLine("New log and a source for DA is  created");
				}
				else
				{
					Console.WriteLine(" source for DA exists already");
				}
			
				// create an instance of EventLog of DA and make some test entries
				EventLog elDA= new EventLog(strLogDA,strMachine,strSourceDA);
				elDA.WriteEntry("Test DA Error",EventLogEntryType.Error);
				elDA.WriteEntry("test DA Information",EventLogEntryType.Information);
				elDA.WriteEntry("test DA Warning",EventLogEntryType.Warning);


				// Create EventLog for the Presentation Layer
				if(!EventLog.SourceExists(strSourcePL,strMachine))
				{
					
					EventLog.CreateEventSource(strSourcePL,strLogPL,strMachine);
					Console.WriteLine("New log and a source for PL is  created");
				}
				else
				{
					Console.WriteLine(" source for PL exists already");
				}
			
				// create an instance of EventLog of PL and make some test entries
				EventLog elPL= new EventLog(strLogPL,strMachine,strSourcePL);
				elPL.WriteEntry("Test PL Error",EventLogEntryType.Error);
				elPL.WriteEntry("test PL Information",EventLogEntryType.Information);

			
			}
			catch(Exception oException)
			{
				Console.WriteLine(oException.Message);
			}

			string strStop= Console.ReadLine();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Switzerland Switzerland
Paul Abraham is a software developer who designs and develops multi-shop systems.

He has received his M.Sc in Mathematics and Computer Science from the FernUniversität Hagen(http://www.fernuni-hagen.de Germany) and his main interests are neural networks and bayesian statistics He lives in Rosenheim (South Germany http://www.rosenheim.de). You can reach him at admin@paul-abraham.com.

Comments and Discussions