writing to Application event log

J

John S

I have written a web service in VB.Net 3. I want to record any exceptions
generated in the Application event log.

For a Windows app, you can use the My.Application.Log.WriteException(ex) and
uncomment a couple of lines in the app.config file.

I can't work out how to do it in a webservice.

Can anyone help?
 
M

Mark Stevens

Try integrating the following:

using System.Diagnostics;

EventLog applicationEventLog = new EventLog("Application", ".",
"KeyName");

applicationEventLog.WriteEntry("Message...", EventLogEntryType.Error);

You will of course need to register the "KeyName" in the registry on
the server(s) using this code.

Hope this help,
Mark


I have written a web service in VB.Net 3. I want to record any exceptions
generated in the Application event log.

For a Windows app, you can use the My.Application.Log.WriteException(ex) and
uncomment a couple of lines in the app.config file.

I can't work out how to do it in a webservice.

Can anyone help?
--
|\ _,,,---,,_ A picture used to be worth a
ZZZzzz /,`.-'`' -. ;-;;, thousand words - then along
|,4- ) )-,_. ,\ ( `'-' came television!
'---''(_/--' `-'\_)

Mark Stevens (mark at thepcsite fullstop co fullstop uk)

This message is provided "as is".
 
M

Mark Stevens

Missed a word out, last sentence should read:

You will of course need to register the "KeyName" in the registry on
the server(s) BEFORE using this code.

And "Keyname" is the source for the error.

Regards,
Mark

Try integrating the following:

using System.Diagnostics;

EventLog applicationEventLog = new EventLog("Application", ".",
"KeyName");

applicationEventLog.WriteEntry("Message...", EventLogEntryType.Error);

You will of course need to register the "KeyName" in the registry on
the server(s) using this code.

Hope this help,
Mark
--
|\ _,,,---,,_ A picture used to be worth a
ZZZzzz /,`.-'`' -. ;-;;, thousand words - then along
|,4- ) )-,_. ,\ ( `'-' came television!
'---''(_/--' `-'\_)

Mark Stevens (mark at thepcsite fullstop co fullstop uk)

This message is provided "as is".
 
S

Steven Cheng [MSFT]

Hi John,

As Mark has suggested, you can use the Tracing and Diagnostics feature of
..NET framework /ASP.NET to perform logging. And it is provider based and
also quite flexible to configure via web.config file. Here are some web
articles introducing this:

#Diagnostics and Logging In ASP.NET
http://www.odetocode.com/Articles/294.aspx

#A Provider-Based Service for ASP.NET Tracing
http://msdn.microsoft.com/en-us/magazine/cc163596.aspx

#Logging JavaScript Errors To ASP.NET
http://james.newtonking.com/archive/2006/05/02/98.aspx


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
 
J

John S

Hi,

Thanks for the help. I wanted to keep the process as close to the way we do
things in Windows Form applications, i.e. still using the
my.application.log.writeexception syntax.

With the information from your posts to start me off, I managed to do the
following:

1.Create a registry Key named after the Webservice name in the
eventlog hierachy.

2. Copy the <system.diagnostics> element from an app.config file,
created by VB for a Windoes App, into the web.config file in the
<configuration> element.

3. Follow the remarks in that section to uncomment a couple of lines
and to change the initializeData attribute to the same name as the new
registry key.

4. Build and Publish the project.

This now seems to work the way I want.

One strange thing occured. I forgot to create the registry key on one
occasion while testing. Instead of causing some sort of untrapped error as I
expected, it appeared to use the key belonging to an existing Web service
that I had already created with a totally different name! Can't explain how,
but provided everything is done properly I have my answer.
 
S

Steven Cheng [MSFT]

Thanks for your reply John,

As for the "creating the registry entry", yes, you'd better always
precreate it before running the application because create registry entry
require higher permision than writting into it. There is a typical issue
that the developer forget to precreate the registry entry and cause the
application report "Access denied" error at runtime when running the
ASP.NET under a restricted account( the common case).

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: =?Utf-8?B?Sm9obiBT?= <[email protected]>
References: <[email protected]>
 
S

Steven Cheng [MSFT]

Hi John,

Do you still have any question on this?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).


--------------------
From: (e-mail address removed) (Steven Cheng [MSFT])
Organization: Microsoft
Date: Fri, 29 Aug 2008 06:42:28 GMT
Subject: RE: writing to Application event log
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top