ASP.NET Application not writing to the Windows Event Log - VB.NET

I have a standalone VB application (compiled to EXE, runs via Scheduled Task) which writes to the Event Log just fine (see code below).

So I grabbed the code, plopped it into a VB code-behind page for my ASP.NET application.  When I pasted the code in I got a "Type EventLog not defined" error and it gave me the suggestion to change it to change "New EventLog("Application")" to "New Diagnostics.EventLog("Application")" which I did (see full code below.

But it still won't write to the event log.  When I debug the application and cause an exception, it hits these lines of code but no Event is written into the Event Log.  Both these applications run on the same Server 2003 box if that matters.

What am I doing wrong? I'm open to any ideas.
                Catch ex As Exception
                    Dim evtLog As New EventLog("Application")
                    evtLog.Source = "Reporting"
                    evtLog.WriteEntry("Error during report execution: " & ex.Message & ".  " & System.Environment.CurrentDirectory, EventLogEntryType.Error)
                End Try
Non-Working Code - ASP.NET VB Code-behind page
Catch ex As Exception
            Dim evtLog As New Diagnostics.EventLog("Application")
            evtLog.Source = "Mailer"
            evtLog.WriteEntry("Error During Mailing" & ex.Message & ".  " & System.Environment.CurrentDirectory, Diagnostics.EventLogEntryType.Error)
            Return False
        End Try

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Just an idea: have you created the source prior to writing the entry?

If Not EventLog.SourceExists("Mailer")
   EventLog.CreateEventSource("Mailer", "Mailer");
End If

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Web Forms are not able to write to Windows System resources such as the Registry or the Event Log, so Class Libraries that access these resources are unavailable to Web Forms.
An alternative suggestion to logging errors can be found at EE question:
Why ASP.NET is not able to write to the EventLog?
As long as the user running the application has the appropiate rights, there is no issue with that.
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Just as a related information, here is how the HealthMonitoring provider can write to the Windows EventLog:

I may have gotten a little ahead of myself in making that statement.  My statement was meaning that you couldn't control Windows system resources on the client end, since  there is no guaranty that the client is Windows.

Sorry, I wouldn't be able to give any advice on manipulation server system resources.  I do believe your error has a lot to do with the difference between Win Forms and Web Forms, however,

We are talking about  an ASP.NET application, so it's 100% assured that the server where it runs is an IIS / Windows server, so it's still unaccurate your comment.

And, hey, I'm not trying to sound bad here, I just think you comment may lead to confusion, so I'm just wanting to clarify.
synapse88Author Commented:
Any advice on this guys?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.