2012-06-26 150 views
1

我想在mvc3应用程序中进行健康监测。mvc3健康监测

我正在使用eventviewer。但我想将这些事件和错误保存到Sql服务器数据库中。

<healthMonitoring enabled="true" heartbeatInterval="10"> 
     <providers> 
    <clear/> 
    <add name="EventLogProvider" type="System.Web.Management.EventLogWebEventProvider,System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" /> 

    <add connectionStringName="LocalSqlServer" maxEventDetailsLength="1073741823" 
     buffer="false" bufferMode="Notification" name="SqlWebEventProviderlane" 
     type="System.Web.Management.SqlWebEventProvider,System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" /> 

    </providers> 

    <profiles> 
    <add name="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" 
       custom="" /> 
      <add name="Critical" minInstances="1" maxLimit="Infinite" minInterval="00:00:00" 
       custom="" /> 
    </profiles> 

    <rules> 
    <clear/> 

    <add name="All Errors Default" eventName="All Events" provider="EventLogProvider" 
     profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" 
     custom="" /> 
    <add name="Failure Audits Default" eventName="Failure Audits" 
     provider="EventLogProvider" profile="Default" minInstances="1" 
     maxLimit="Infinite" minInterval="00:01:00" custom="" /> 
    </rules> 

    <eventMappings> 
    <clear/> 
    <add name="All Events" type="System.Web.Management.WebBaseEvent,System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" 
      startEventCode="0" endEventCode="2147483647" /> 
      <add name="All Errors" type="System.Web.Management.WebBaseErrorEvent,System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" 
     startEventCode="0" endEventCode="2147483647" /> 
     </eventMappings> 

</healthMonitoring> 

如何做到这一点?

回答

0

在规则部分,你必须参考同名称的提供“SqlWebEventProviderlane”:

<add name="All Errors Default" eventName="All Events" provider="SqlWebEventProviderlane" 
    profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" 
    custom="" /> 

然后,你必须提供与名称的连接字符串“LocalSqlServer”一节中,这点到你的数据库。

<connectionStrings> 
    <add name="LocalSqlServer" connectionString="data source=serverName;initial catalog=yourDataBase;..."/> 
</connectionStrings> 

而且您必须使用aspnet_regsql工具准备数据库。