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.
WORKING CODE - Standalone VB EXE
 
                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)
                    evtLog.Close()
                    evtLog.Dispose()
                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)
            evtLog.Close()
            evtLog.Dispose()
            Return False
        End Try

Open in new window

synapse88Asked:
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.

Juan_BarreraCommented:
Hi,

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

0

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
TechSingerCommented:
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:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23590298.html
 
0
Juan_BarreraCommented:
TechSinger,
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.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Juan_BarreraCommented:
Just as a related information, here is how the HealthMonitoring provider can write to the Windows EventLog: http://msdn.microsoft.com/en-us/library/system.web.management.eventlogwebeventprovider.aspx

0
TechSingerCommented:
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,
0
Juan_BarreraCommented:
TechSInger,

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.
0
synapse88Author Commented:
Any advice on this guys?
0
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.

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.