writing to Application event log

Discussion in 'ASP .Net Web Services' started by John S, Aug 27, 2008.

  1. John S

    John S Guest

    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?
     
    John S, Aug 27, 2008
    #1
    1. Advertising

  2. John S

    Mark Stevens Guest

    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


    On Wed, 27 Aug 2008 06:48:01 -0700, John S <>
    wrote:

    >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".
     
    Mark Stevens, Aug 27, 2008
    #2
    1. Advertising

  3. John S

    Mark Stevens Guest

    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

    On Wed, 27 Aug 2008 16:23:14 +0100, Mark Stevens <>
    wrote:

    >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
    >
    >
    >On Wed, 27 Aug 2008 06:48:01 -0700, John S <>
    >wrote:
    >
    >>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".
     
    Mark Stevens, Aug 27, 2008
    #3
  4. 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:
    .

    ==================================================
    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.



    --------------------
    >From: =?Utf-8?B?Sm9obiBT?= <>
    >Subject: writing to Application event log
    >Date: Wed, 27 Aug 2008 06:48:01 -0700


    >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?
    >
     
    Steven Cheng [MSFT], Aug 28, 2008
    #4
  5. John S

    John S Guest

    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.
     
    John S, Aug 28, 2008
    #5
  6. 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:
    .

    ==================================================
    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?= <>
    >References: <>

    <>
    >Subject: RE: writing to Application event log
    >Date: Thu, 28 Aug 2008 02:20:00 -0700


    > 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.
    >
    >
     
    Steven Cheng [MSFT], Aug 29, 2008
    #6
  7. 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:
    .


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


    >
    >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:
    >.
    >
    >==================================================
    >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?= <>
    >>References: <>

    ><>
    >>Subject: RE: writing to Application event log
    >>Date: Thu, 28 Aug 2008 02:20:00 -0700

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

    >
    >
     
    Steven Cheng [MSFT], Sep 2, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henrik_the_boss
    Replies:
    0
    Views:
    2,695
    Henrik_the_boss
    Nov 5, 2003
  2. =?Utf-8?B?VG9tIFdpbmdlcnQ=?=

    My.Log.Writeexception not writing to Application Event Log.

    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=, Jan 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,400
    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=
    Jan 20, 2006
  3. =?Utf-8?B?SmVmZkRvdE5ldA==?=

    Writing to a registered source in the Application event log with I

    =?Utf-8?B?SmVmZkRvdE5ldA==?=, Jul 12, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    6,360
    =?Utf-8?B?SmVmZkRvdE5ldA==?=
    Aug 1, 2006
  4. coconet
    Replies:
    5
    Views:
    5,757
    Steven Cheng[MSFT]
    Feb 12, 2008
  5. Tom Wingert
    Replies:
    0
    Views:
    359
    Tom Wingert
    Jan 12, 2006
Loading...

Share This Page