Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. [newbie] EventLog log = new EventLog() does not work within catch {} block

[newbie] EventLog log = new EventLog() does not work within catch {} block

Scheduled Pinned Locked Moved C#
csharphelpdebuggingasp-netvisual-studio
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jon 80
    wrote on last edited by
    #1

    I'm trying to run this code within Visual Studio 2010, however, having set a breakpoint at line 39, the execution does not seem to get to line 39 where I have set a break point. As a matter of fact, when checking under Visual Studio 2010 Server Explorer > Servers > {puter name} > Application > ASP.NET 4.0.30319.0, there are no relevant events written. I also tried checking within the Windows Event Viewer. For Win XP (Control Panel > Administrative Tools > Event Viewer > Application sub node). Is this a bug with .NET 4 or Visual Studio 2010? Does this issue happen to anyone else? :confused:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Drawing;
    using System.Diagnostics;

    public partial class ErrorTestLog : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void cmdCompute\_Click(object sender, EventArgs e)
    {
        try
        {
            decimal a, b, result;
            a = Decimal.Parse(txtA.Text);
            b = Decimal.Parse(txtB.Text);
            result = a / b;
            lblResult.Text = result.ToString();
            lblResult.ForeColor = Color.Black;
        }
        catch (Exception err)
        {
            lblResult.Text = "<b>Message:</b> " + err.Message + "<br /><br />";
            lblResult.Text += "<b>Source:</b> " + err.Source + "<br /><br />";
            lblResult.Text += "<b>Stack Trace:</b> " + err.StackTrace;
            lblResult.ForeColor = Color.Red;
    
            // Write the information to the event log.
            EventLog log = new EventLog();
            log.Source = "DivisionPage";
            log.WriteEntry(err.Message, EventLogEntryType.Error);
        }
    
    
    }
    

    }

    NOTE: 1. Beginning ASP.NET 3.5 in C# in 2008 - From Novice to Professional (ISBN: 978-1-59059-891-7) P.268 (306)

    Jon

    E A 2 Replies Last reply
    0
    • J jon 80

      I'm trying to run this code within Visual Studio 2010, however, having set a breakpoint at line 39, the execution does not seem to get to line 39 where I have set a break point. As a matter of fact, when checking under Visual Studio 2010 Server Explorer > Servers > {puter name} > Application > ASP.NET 4.0.30319.0, there are no relevant events written. I also tried checking within the Windows Event Viewer. For Win XP (Control Panel > Administrative Tools > Event Viewer > Application sub node). Is this a bug with .NET 4 or Visual Studio 2010? Does this issue happen to anyone else? :confused:

      using System;
      using System.Data;
      using System.Configuration;
      using System.Collections;
      using System.Web;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Web.UI.WebControls.WebParts;
      using System.Web.UI.HtmlControls;
      using System.Drawing;
      using System.Diagnostics;

      public partial class ErrorTestLog : System.Web.UI.Page
      {
      protected void Page_Load(object sender, EventArgs e)
      {

      }
      protected void cmdCompute\_Click(object sender, EventArgs e)
      {
          try
          {
              decimal a, b, result;
              a = Decimal.Parse(txtA.Text);
              b = Decimal.Parse(txtB.Text);
              result = a / b;
              lblResult.Text = result.ToString();
              lblResult.ForeColor = Color.Black;
          }
          catch (Exception err)
          {
              lblResult.Text = "<b>Message:</b> " + err.Message + "<br /><br />";
              lblResult.Text += "<b>Source:</b> " + err.Source + "<br /><br />";
              lblResult.Text += "<b>Stack Trace:</b> " + err.StackTrace;
              lblResult.ForeColor = Color.Red;
      
              // Write the information to the event log.
              EventLog log = new EventLog();
              log.Source = "DivisionPage";
              log.WriteEntry(err.Message, EventLogEntryType.Error);
          }
      
      
      }
      

      }

      NOTE: 1. Beginning ASP.NET 3.5 in C# in 2008 - From Novice to Professional (ISBN: 978-1-59059-891-7) P.268 (306)

      Jon

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      Does your exception block throw an exception? Do you have a generic exception handler? Does your IIS user have access to write to the event log? Did you use System.Diagnostics.EventLog.CreateEventSource and System.Diagnostics.EventLog.WriteEntry? (Probably not, since you new'd EventLog)

      Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

      J 1 Reply Last reply
      0
      • J jon 80

        I'm trying to run this code within Visual Studio 2010, however, having set a breakpoint at line 39, the execution does not seem to get to line 39 where I have set a break point. As a matter of fact, when checking under Visual Studio 2010 Server Explorer > Servers > {puter name} > Application > ASP.NET 4.0.30319.0, there are no relevant events written. I also tried checking within the Windows Event Viewer. For Win XP (Control Panel > Administrative Tools > Event Viewer > Application sub node). Is this a bug with .NET 4 or Visual Studio 2010? Does this issue happen to anyone else? :confused:

        using System;
        using System.Data;
        using System.Configuration;
        using System.Collections;
        using System.Web;
        using System.Web.Security;
        using System.Web.UI;
        using System.Web.UI.WebControls;
        using System.Web.UI.WebControls.WebParts;
        using System.Web.UI.HtmlControls;
        using System.Drawing;
        using System.Diagnostics;

        public partial class ErrorTestLog : System.Web.UI.Page
        {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void cmdCompute\_Click(object sender, EventArgs e)
        {
            try
            {
                decimal a, b, result;
                a = Decimal.Parse(txtA.Text);
                b = Decimal.Parse(txtB.Text);
                result = a / b;
                lblResult.Text = result.ToString();
                lblResult.ForeColor = Color.Black;
            }
            catch (Exception err)
            {
                lblResult.Text = "<b>Message:</b> " + err.Message + "<br /><br />";
                lblResult.Text += "<b>Source:</b> " + err.Source + "<br /><br />";
                lblResult.Text += "<b>Stack Trace:</b> " + err.StackTrace;
                lblResult.ForeColor = Color.Red;
        
                // Write the information to the event log.
                EventLog log = new EventLog();
                log.Source = "DivisionPage";
                log.WriteEntry(err.Message, EventLogEntryType.Error);
            }
        
        
        }
        

        }

        NOTE: 1. Beginning ASP.NET 3.5 in C# in 2008 - From Novice to Professional (ISBN: 978-1-59059-891-7) P.268 (306)

        Jon

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        Go though this article.

        J 1 Reply Last reply
        0
        • E Ennis Ray Lynch Jr

          Does your exception block throw an exception? Do you have a generic exception handler? Does your IIS user have access to write to the event log? Did you use System.Diagnostics.EventLog.CreateEventSource and System.Diagnostics.EventLog.WriteEntry? (Probably not, since you new'd EventLog)

          Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

          J Offline
          J Offline
          jon 80
          wrote on last edited by
          #4

          Does your exception block throw an exception? No, but throwing the exception prior to calling the event log makes the logging code unreachable, and, this works fine within Visual Studio 2010. Do you have a generic exception handler? No, because it is not required for now. Does your IIS user have access to write to the event log? I am using Administrator on a local PC, what user does VS 2010 use (to confirm)? Did you use System.Diagnostics.EventLog.CreateEventSource and System.Diagnostics.EventLog.WriteEntry? (Probably not, since you new'd EventLog) System.Diagnostics.CreateEventSource is not even shown up within Visual Studio 2010, even though it's a static method. Problem with Intellisense maybe.

          Jon

          1 Reply Last reply
          0
          • A Abhinav S

            Go though this article.

            J Offline
            J Offline
            jon 80
            wrote on last edited by
            #5

            It's interesting. I'm noting that when I load my testpage on the browser (Google Chrome, Mozilla FF) the page remains 'waiting for cache...' when building it. Code here.[^] Screendump here.[^ :confused: Related links Article 1[^] Article 2

            Jon

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups