Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Web App Logging using Health Monitoring not working
    primarykey
    data
    text
    <p>I am using VS2005 C# 2.0 and SQL Server 2005.</p> <p>I am referring to <a href="http://msdn.microsoft.com/en-us/library/ff650305.aspx">this</a> guide on configuring Health Monitoring.</p> <p>At the end of the guide, there will be a button on <em>Default.aspx</em> and on_Click of the button, a new record will be inserted into my SQL table.</p> <p>However, when my button is pressed, there is no record inserted in the table.</p> <p>I am unsure of what the error as there are no error messages shown, so I guess the only way is to trial and error on where I have gone wrong.</p> <p><strong>P.S.</strong> I am unable to compile <code>MyWebEvents</code> class library because there is no output. In my main web application, I added reference dll from the <em>bin</em> folder of my <em>MyWebEvents</em> project file. Is the DLL i referenced valid for use, or is there a step I missed in compiling?</p> <p>Below are the codes which I ran, with reference to the microsoft website:</p> <hr> <p><code>MyCriticalEvent.cs</code> in <strong>MyWebEvents</strong> class library:</p> <pre><code>namespace MyWebEvents { public class MyCriticalEvent : WebAuditEvent { private string userID; private string authType; private bool isAuthenticated; public MyCriticalEvent(string msg, object eventSource, int eventCode) : base(msg, eventSource, eventCode) { // Obtain the HTTP Context and store authentication details userID = HttpContext.Current.User.Identity.Name; authType = HttpContext.Current.User.Identity.AuthenticationType; isAuthenticated = HttpContext.Current.User.Identity.IsAuthenticated; } public MyCriticalEvent(string msg, object eventSource, int eventCode, int eventDetailCode) : base(msg, eventSource, eventCode, eventDetailCode) { userID = HttpContext.Current.User.Identity.Name; authType = HttpContext.Current.User.Identity.AuthenticationType; isAuthenticated = HttpContext.Current.User.Identity.IsAuthenticated; } public override void FormatCustomEventDetails(WebEventFormatter formatter) { base.FormatCustomEventDetails(formatter); formatter.AppendLine("User ID: " + userID); formatter.AppendLine("Authentication Type: " + authType); formatter.AppendLine("User Authenticated: " + isAuthenticated.ToString()); formatter.AppendLine("Activity Description: Critical Operation"); } } } </code></pre> <hr> <p><code>Default.aspx.cs</code> in <strong>Main Web Application</strong>:</p> <pre><code>public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { MyCriticalEvent testEvent = new MyCriticalEvent( "Critical Operation Performed", this, WebEventCodes.WebExtendedBase + 1); testEvent.Raise(); } } </code></pre> <hr> <p><code>Web.config</code> in <strong>Main Web Applicatiion</strong>:</p> <pre><code>&lt;configuration&gt; &lt;appSettings/&gt; &lt;connectionStrings&gt; &lt;add name="MySqlConnection" connectionString="Data Source=&lt;IP&gt;;Initial Catalog=&lt;DB NAME&gt;;Persist Security Info=True;User ID=&lt;admin username&gt;;Password=&lt;admin password&gt;" providerName="System.Data.SqlClient"/&gt; &lt;/connectionStrings&gt; &lt;system.web&gt; &lt;healthMonitoring enabled="true" heartbeatInterval="0"&gt; &lt;bufferModes&gt; &lt;clear/&gt; &lt;add name="Logging" maxBufferSize="1000" maxFlushSize="200" urgentFlushThreshold="800" regularFlushInterval="00:05:00" urgentFlushInterval="00:01:00" maxBufferThreads="1"/&gt; &lt;/bufferModes&gt; &lt;providers&gt; &lt;clear/&gt; &lt;add name="MySqlWebEventProvider" type="System.Web.Management.SqlWebEventProvider" connectionStringName="MySqlConnection" maxEventDetailsLength="1073741823" buffer="true" bufferMode="Logging"/&gt; &lt;/providers&gt; &lt;eventMappings&gt; &lt;clear/&gt; &lt;add name="All Audits" type="System.Web.Management.WebAuditEvent" startEventCode="0" endEventCode="2147483647"/&gt; &lt;add name="All Errors" type="System.Web.Management.WebBaseErrorEvent" startEventCode="0" endEventCode="2147483647"/&gt; &lt;/eventMappings&gt; &lt;profiles&gt; &lt;clear/&gt; &lt;add name="Audit Logs" minInstances="1" maxLimit="Infinite" minInterval="00:00:15"/&gt; &lt;add name="Error Logs" minInstances="1" maxLimit="Infinite" minInterval="00:00:15"/&gt; &lt;/profiles&gt; &lt;rules&gt; &lt;clear/&gt; &lt;add name="All Audits Default" eventName="All Audits" provider="MySqlWebEventProvider" profile="Audit Logs"/&gt; &lt;add name="All Errors Default" eventName="All Errors" provider="MySqlWebEventProvider" profile="Error Logs"/&gt; &lt;/rules&gt; &lt;/healthMonitoring&gt; &lt;/system.web&gt; &lt;/configuration&gt; </code></pre> <hr> <p><img src="https://i.stack.imgur.com/mejMc.png" alt="enter image description here"></p> <hr> <p>Table in my database:</p> <p><img src="https://i.stack.imgur.com/aSAXy.png" alt="enter image description here"></p> <hr> <p>Error raised in the Event log if SQL Connection is broken:</p> <p><code>The following exception was thrown by the web event provider 'MySqlWebEventProvider' in the application '/TestLogSite' (in an application lifetime a maximum of one exception will be logged per provider instance):</code></p> <hr> <p><strong>Problem Summary</strong>: When <code>button1</code> on <em>Default.aspx.cs</em> is clicked, no log records were inserted in the <code>aspnet_WebEvent_Event</code> table.</p> <p>May I know which part of my code have I gone wrong or missed out?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload