Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 905
  • Last Modified:

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

0
synapse88
Asked:
synapse88
  • 4
  • 2
1 Solution
 
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
 
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now