using global asax

i'm currently writing to a custom event log in the code behinds but want to switch it over to the global asax file -- just not sure how to do it. I want the global asax to check for the custom event log so each page doesn't have to do it.
//default page code behind

using System.Diagnostics;

public partial class _Default : System.Web.UI.Page
{
 string sWebAppName = "TestSite";


public string webAppName
{
 get { return sWebAppName; }
 set { sWebAppName = value; }
}


protected void Page_Load(object sender, EventArgs e)
{
 checkEventLog();

//code to generate an error
}


void checkEventLog()
{
 if (!EventLog.SourceExists(webAppName)) EventLog.CreateEventSource(webAppName, webAppName);
}

}



//-----------------------------------------

//how do i use the global asax?

<%@ Import Namespace="System.Diagnostics" %>

<script runat="server">

Application["webAppName"] = "TestSite";

void Application_Start(object sender, EventArgs e) 
{
 if (!EventLog.SourceExists(webAppName)) EventLog.CreateEventSource(webAppName, webAppName);
}

</script>

Open in new window

vicominAsked:
Who is Participating?
 
vicominAuthor Commented:
I'm doing something similar - just need to know how to do a few things in the global asax like how to check if the log exists and how to use a variable.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.