ASP.NET C# Writing to Event Log Problem
Hi guys,
How r u doing there? I got a problem here ! The following is the C# code:
<%@ Import Namespace="System.Diagnostics" %>
<script Language="c#" runat="server" >
void EntrytoLog()
{
int[] array = new int[9];
for(int intCounter=0; intCounter <= 9;intCounter++)
{
array[intCounter] = intCounter;
Response.Write("The value of the counter is:" + intCounter + "<br>");
}
}
void Page_Error(object sender, EventArgs e)
{
string errorMessage = "Error occurred" + Server.GetLastError();
Server.ClearError();
string LogName = "MyApplicationLog";
string SourceName = "MyApplicationSource";
if (!(EventLog.SourceExists(SourceName)))
{
EventLog.CreateEventSource(SourceName, LogName);
}
// Insert into Event Log;
EventLog MyLog = new EventLog();
MyLog.Source = SourceName;
MyLog.WriteEntry(errorMessage, EventLogEntryType.Error);
}
</script>
<%
EntrytoLog();
%>
which I got it from Wrox Beginning ASP.NET using C# book. When try to execute the page, I got the following error message:
================================================== ===============
Exception Details: System.Security.SecurityException: Requested registry access is not allowed.
Source Error:
Line 18: if (!(EventLog.SourceExists(SourceName)))
Line 19: {
Line 20: EventLog.CreateEventSource(SourceName, LogName);
Line 21: }
Line 22: // Insert into Event Log;
================================================== ===============
I am loggin in as administrator !!
Pls help !!
|