How to write to event Log with in my web application

mgmhicks
mgmhicks used Ask the Experts™
on
I have tried this code to write to the event log with no success.  Didn't think it would be that easy.  Could someone send me in the right direction.

imports system.diagnostics


 Dim myLog As New EventLog("")
                    myLog.Source = "ResidentPortal"
                    myLog.WriteEntry("Invalid Password Attempt", EventLogEntryType.FailureAudit)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Éric MoreauSenior .Net Consultant
Top Expert 2016
Commented:
You surely don't have permissions (or IIS doesn't have permission) to do it. Check https://support.microsoft.com/en-us/kb/2028427
Top Expert 2015
Commented:
Think of the mess if web pages could write to the EventLog.

The EventLog is there to diagnose what happens on the computer. So it is available to the operating system and to the applications that run on that computer. A Web application runs on one computer, but displays on another one.

Problems do not occur on the computer on which the page is displayed, so the log is not available there. Think of all the scrap that would be put there and the mess it would become if every web page could write there. It's already enough of a mess with cookies.

Because the web application runs on the server, you might think that the right would be given on the server computer. But think of the mess there to. If 10,000 users request a page that writes to the event log, you would end up with 10,000 entries similar entries in the log. That would render the log useless for the applications that properly use the log.

If you want to log some information, do it in a database on the server side. On the user side, post a message on the screen.
Look into NLog. Very easy to use, highly customizable and quite reliable.

Author

Commented:
Didn't end up doing it, but all points were either valid or helpful.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial