EDN Admin
Well-known member
Hi
I am writing a Dashboard type application that collects statistics for one of customer facing applications and displays the statistics to various stakeholders. The application is working fine, but when trying to log exceptions to the Event Log I am getting the following error:
<b>An object reference is required for the non-static field, method, or property</b>
I have a class defined as follows for the logging of the event, but when I build the solution, the error above is displayed. It is probably something really simple, but I just cannot figure it out.
<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap <tbody><tr><td><font style="font-size:11px </font><font style="color:blue namespace</font><font style="font-size:11px Netbank.Dashboard.Website.MiddleTier.CAP </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> <font style="color:blue public</font><font style="font-size:11px </font><font style="color:blue class</font><font style="font-size:11px capDashboard </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> <font style="color:blue private</font><font style="font-size:11px </font><font style="color:blue void</font><font style="font-size:11px LogEvent(</font><font style="color:blue string</font><font style="font-size:11px Message, EventLogEntryType Level, </font><font style="color:blue int</font><font style="font-size:11px EventID) </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> String DashboardLog = <font style="color:blue "Dashboard"</font><font style="font-size:11px ; </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) String DashboardLogSource = <font style="color:blue "Dashboard.Collection"</font><font style="font-size:11px ; </font></td></tr><tr><td> EventLog dbdDashboardEventLog = <font style="color:blue new</font><font style="font-size:11px EventLog(DashboardLog); </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) dbdDashboardEventLog.Source = DashboardLogSource; </td></tr><tr><td> </td></tr><tr><td style="background-color:rgb(247, 247, 247) <font style="color:blue if</font><font style="font-size:11px (!EventLog.SourceExists(DashboardLog)) </font></td></tr><tr><td> { </td></tr><tr><td style="background-color:rgb(247, 247, 247) EventLog.CreateEventSource(DashboardLogSource, DashboardLog); </td></tr><tr><td> dbdDashboardEventLog.WriteEntry(Message, Level, EventID); </td></tr><tr><td style="background-color:rgb(247, 247, 247) } </td></tr><tr><td> <font style="color:blue else</font><font style="font-size:11px </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> dbdDashboardEventLog.WriteEntry(Message, Level, EventID); </td></tr><tr><td style="background-color:rgb(247, 247, 247) } </td></tr><tr><td> } </td></tr></tbody></table>
And then in the try block I have the code for the application, which is working 100% and in the catch block, I am writing the Event Log Entry as follows:
<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap <tbody><tr><td><font style="font-size:11px </font><font style="color:blue public</font><font style="font-size:11px </font><font style="color:blue static</font><font style="font-size:11px Hashtable GetFieldData() </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> <font style="color:blue try</font><font style="font-size:11px </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> </td></tr><tr><td style="background-color:rgb(247, 247, 247) } </td></tr><tr><td> </td></tr><tr><td style="background-color:rgb(247, 247, 247) <font style="color:blue catch</font><font style="font-size:11px (Exception ex) </font></td></tr><tr><td> { </td></tr><tr><td style="background-color:rgb(247, 247, 247) LogEvent(<font style="color:blue "Unable to Retrieve CAP data for the Main CAP Dashboard."</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "Message:"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + ex.Message + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "Stack Trace:"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + ex.StackTrace, EventLogEntryType.Error, 29953); </font></td></tr><tr><td> } </td></tr></tbody></table>
<hr class="sig Systems Analyst
View the full article
I am writing a Dashboard type application that collects statistics for one of customer facing applications and displays the statistics to various stakeholders. The application is working fine, but when trying to log exceptions to the Event Log I am getting the following error:
<b>An object reference is required for the non-static field, method, or property</b>
I have a class defined as follows for the logging of the event, but when I build the solution, the error above is displayed. It is probably something really simple, but I just cannot figure it out.
<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap <tbody><tr><td><font style="font-size:11px </font><font style="color:blue namespace</font><font style="font-size:11px Netbank.Dashboard.Website.MiddleTier.CAP </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> <font style="color:blue public</font><font style="font-size:11px </font><font style="color:blue class</font><font style="font-size:11px capDashboard </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> <font style="color:blue private</font><font style="font-size:11px </font><font style="color:blue void</font><font style="font-size:11px LogEvent(</font><font style="color:blue string</font><font style="font-size:11px Message, EventLogEntryType Level, </font><font style="color:blue int</font><font style="font-size:11px EventID) </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> String DashboardLog = <font style="color:blue "Dashboard"</font><font style="font-size:11px ; </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) String DashboardLogSource = <font style="color:blue "Dashboard.Collection"</font><font style="font-size:11px ; </font></td></tr><tr><td> EventLog dbdDashboardEventLog = <font style="color:blue new</font><font style="font-size:11px EventLog(DashboardLog); </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) dbdDashboardEventLog.Source = DashboardLogSource; </td></tr><tr><td> </td></tr><tr><td style="background-color:rgb(247, 247, 247) <font style="color:blue if</font><font style="font-size:11px (!EventLog.SourceExists(DashboardLog)) </font></td></tr><tr><td> { </td></tr><tr><td style="background-color:rgb(247, 247, 247) EventLog.CreateEventSource(DashboardLogSource, DashboardLog); </td></tr><tr><td> dbdDashboardEventLog.WriteEntry(Message, Level, EventID); </td></tr><tr><td style="background-color:rgb(247, 247, 247) } </td></tr><tr><td> <font style="color:blue else</font><font style="font-size:11px </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> dbdDashboardEventLog.WriteEntry(Message, Level, EventID); </td></tr><tr><td style="background-color:rgb(247, 247, 247) } </td></tr><tr><td> } </td></tr></tbody></table>
And then in the try block I have the code for the application, which is working 100% and in the catch block, I am writing the Event Log Entry as follows:
<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap <tbody><tr><td><font style="font-size:11px </font><font style="color:blue public</font><font style="font-size:11px </font><font style="color:blue static</font><font style="font-size:11px Hashtable GetFieldData() </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> <font style="color:blue try</font><font style="font-size:11px </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) { </td></tr><tr><td> </td></tr><tr><td style="background-color:rgb(247, 247, 247) } </td></tr><tr><td> </td></tr><tr><td style="background-color:rgb(247, 247, 247) <font style="color:blue catch</font><font style="font-size:11px (Exception ex) </font></td></tr><tr><td> { </td></tr><tr><td style="background-color:rgb(247, 247, 247) LogEvent(<font style="color:blue "Unable to Retrieve CAP data for the Main CAP Dashboard."</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "Message:"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + ex.Message + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "Stack Trace:"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + </font><font style="color:blue "n"</font><font style="font-size:11px + ex.StackTrace, EventLogEntryType.Error, 29953); </font></td></tr><tr><td> } </td></tr></tbody></table>
<hr class="sig Systems Analyst
View the full article