本文介绍了使用健康监控ASP.NET Web应用程序日志记录不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VS2005 C#2.0和SQL Server 2005。

I am using VS2005 C# 2.0 and SQL Server 2005.

我指的是指南。

在引导结束时,将会有一个按钮的 Default.aspx的的和按钮的on_Click,一个新的记录将被插入到我的SQL表。

At the end of the guide, there will be a button on Default.aspx and on_Click of the button, a new record will be inserted into my SQL table.

然而,当我的按钮pressed,没有在表中插入的记录。

However, when my button is pressed, there is no record inserted in the table.

我不确定错误什么的有没有显示错误信息,所以我想的唯一方法是试错在何处我已经错了。

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.S。我无法编译 MyWebEvents 类库因为没有输出。在我的主要的Web应用程序,我加在的的我的 MyWebEvents的文件夹的项目文件中引用的DLL。是我引用的有效使用DLL,或者是有我在编译错过了一步?

P.S. I am unable to compile MyWebEvents class library because there is no output. In my main web application, I added reference dll from the bin folder of my MyWebEvents project file. Is the DLL i referenced valid for use, or is there a step I missed in compiling?

下面是codeS,我跑了,参考微软网站:

Below are the codes which I ran, with reference to the microsoft website:

MyCriticalEvent.cs MyWebEvents 类库:

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");
    }
}
}


Default.aspx.cs 主要的Web应用程序

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();
}
}


的Web.config 主要网站Applicatiion

<configuration>
    <appSettings/>
    <connectionStrings>
        <add name="MySqlConnection" connectionString="Data Source=<IP>;Initial Catalog=<DB NAME>;Persist Security Info=True;User ID=<admin username>;Password=<admin password>" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <system.web>
                <healthMonitoring enabled="true" heartbeatInterval="0">
        <bufferModes>
            <clear/>
            <add name="Logging" maxBufferSize="1000" maxFlushSize="200" urgentFlushThreshold="800" regularFlushInterval="00:05:00" urgentFlushInterval="00:01:00" maxBufferThreads="1"/>
        </bufferModes>
        <providers>
            <clear/>
            <add name="MySqlWebEventProvider" type="System.Web.Management.SqlWebEventProvider" connectionStringName="MySqlConnection" maxEventDetailsLength="1073741823" buffer="true" bufferMode="Logging"/>
        </providers>
        <eventMappings>
            <clear/>
            <add name="All Audits" type="System.Web.Management.WebAuditEvent" startEventCode="0" endEventCode="2147483647"/>
            <add name="All Errors" type="System.Web.Management.WebBaseErrorEvent" startEventCode="0" endEventCode="2147483647"/>
        </eventMappings>
        <profiles>
            <clear/>
            <add name="Audit Logs" minInstances="1" maxLimit="Infinite" minInterval="00:00:15"/>
            <add name="Error Logs" minInstances="1" maxLimit="Infinite" minInterval="00:00:15"/>
        </profiles>
        <rules>
            <clear/>
            <add name="All Audits Default" eventName="All Audits" provider="MySqlWebEventProvider" profile="Audit Logs"/>
            <add name="All Errors Default" eventName="All Errors" provider="MySqlWebEventProvider" profile="Error Logs"/>
        </rules>
    </healthMonitoring>
    </system.web>
</configuration>



表在我的数据库:

如果SQL连接被中断,在事件日志中引发错误:

Error raised in the Event log if SQL Connection is broken:

下面的例外是由网络事件提供应用程序/ TestLogSite'抛出'MySqlWebEventProvider(在应用程序生命周期最多只有一个例外,将每个提供程序实例记录):

问题摘要:当按钮1 上的 Default.aspx.cs 的点击,没有日志记录被插入在 aspnet_WebEvent_Event 表。

Problem Summary: When button1 on Default.aspx.cs is clicked, no log records were inserted in the aspnet_WebEvent_Event table.

可以让我知道我的code的一部分,我已经错了还是错过了?

May I know which part of my code have I gone wrong or missed out?

推荐答案

如果你想看到它的时候了尝试禁用缓冲

If you want to see it right away try disabling buffering

<add name="MySqlWebEventProvider" type="System.Web.Management.SqlWebEventProvider" connectionStringName="MySqlConnection" maxEventDetailsLength="1073741823" buffer="true" bufferMode="Logging"/>

更改

<add name="MySqlWebEventProvider" type="System.Web.Management.SqlWebEventProvider" connectionStringName="MySqlConnection" maxEventDetailsLength="1073741823" buffer="false" bufferMode="Logging"/>

这应该停止所造成的缓冲延迟,你应该看到的行出现的时候了。

This should stop the delay caused by buffering and you should see the rows appear right away.

另外,你可能要减少你的minInterval的配置文件,以快速的东西,如00:00:01:)

Plus you may want to decrease your minInterval on the profiles to something quick like "00:00:01" :)

您可以阅读更多关于缓冲位置:

You can read more about buffering here:

在实际系统它也许是一个好主意离开缓冲到位的情况下,你认为你的SQL服务器可能有很多事件射击超载。

On a live system it maybe a good idea to leave buffering in place in case you think your SQL server might get overloaded with lots of events firing.

香港专业教育学院发现,我可以强制它被保存到日志:

Ive found i can force it save to the log by:

1:开始在Visual Studio项目
2:单击按钮
3:停止该项目,然后再次启动
4:检查在数据库中,你应该看到事件记录

1 : start your project in visual studio2 : click the button3 : Stop the project and then start it again4 : Check in the database you should see an event logged

这篇关于使用健康监控ASP.NET Web应用程序日志记录不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 07:47