如何让 ELMAH 记录到 MySQL?

发布于 2024-12-24 18:00:23 字数 226 浏览 3 评论 0原文

我们已将 ELMAH 与 ASP.NET MVC 3 集成,作为记录应用程序错误的一种方式。但是,我们还没有持久化日志。为此,我们希望将 ELMAH 的日志条目存储在 MySQL 中,因为我们已经将此数据库服务器的实例用于其他目的。

我们如何配置 ELMAH 以使其日志与 MySQL 保持一致?

We have integrated ELMAH with ASP.NET MVC 3, as a way to log application errors. However, we do not yet persist the log. To this end, we'd like to store ELMAH's log entries in MySQL, as we're already using an instance of this database server for other purposes.

How do we configure ELMAH so that it persists its log with MySQL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝海似她心 2024-12-31 18:00:23

您可以在 MySQL 上安装 NuGet 包 ELMAH

PM>安装包elmah.mysql

您必须对其进行配置。来自Elmah.MySql.txt,它是包的一部分。

请注意,为了完成 ELMAH.MySql 的安装,您必须执行以下操作:

  1. 确保您已从 http://dev.mysql.com/downloads/connector/net/ (这是可选的,因为我们已经包含了 MySql.Data.dll,如果您下载最新的连接器您不需要我们的版本)
  2. 针对数据库运行 Elmah.MySql.sql 脚本
  3. 使用 elmah 中的正确设置编辑 web.config 以连接到数据库

更多信息

You can install the NuGet package ELMAH on MySQL

PM> Install-Package elmah.mysql

You have to configure that. from Elmah.MySql.txt which is part of the package.

Please note that in order to complete the installation of ELMAH.MySql you will have to do the following:

  1. Make sure you have the latest MySQL Connector installed from http://dev.mysql.com/downloads/connector/net/ (this is optional, since we already include MySql.Data.dll, if you download the latest connector you don't need our version)
  2. Run the Elmah.MySql.sql script against your database
  3. Edit your web.config with the correct settings in the elmah to connect to your database

More Information

生生漫 2024-12-31 18:00:23

这就是我配置 elmah 写入 MySQL 的方式。在 Visual Studio 中...

  1. 安装 Elmah Nuget 包
  2. 安装 Elmah.MySQL Nuget 包

这两个安装对 web.config 文件进行了一些更改,这些是要查找的相关部分:

<elmah>
<security allowRemoteAccess="false" />
<errorLog type="Elmah.MySqlErrorLog, Elmah" connectionStringName="elmah-mysql" />
</elmah>

这需要一个新的连接字符串... elmah 已添加对于我的模板,我只需要输入正确的凭据:

<connectionStrings>
<add name="DevDB" connectionString="Server=localhost; Database=NZ; Uid=myuserid; Pwd=mypwd" providerName="MySql.Data.MySqlClient"/>
<add name="elmah-mysql" connectionString="Server=localhost; Database=elmah; Uid=myuserid; Pwd=mypwd" providerName="MySql.Data.MySqlClient" />
</connectionStrings>

如果您使用的是 EntityFramework,请确保 EntityFramework 提供程序是正确的,

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>

并且 DbProviderFactories 是正确的

<system.data>
<DbProviderFactories>
  <remove invariant="MySql.Data.MySqlClient" />
  <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
  1. 从这里获取相关的 SQL 脚本:elmah.Mysql 并运行脚本来创建表和程序。另请注意,这些脚本默认情况下会创建一个名为 elmah 的数据库...如果要更改数据库名称,请确保它与上面的连接字符串中的数据库一致。

这就是我所要做的让它运行​​起来。

注意:需要注意的一件事是在上面的连接字符串中使用小写字符作为数据库名称,因为 MySQL 数据库名称是小写的...它最初对我来说是大写的,但后来它坏了,我不得不更换它。

This is how I have configured elmah to write to MySQL. In Visual Studio...

  1. Install Elmah Nuget Package
  2. Install Elmah.MySQL Nuget Package

These two installation make some changes to the web.config file, these are the relevant sections to look for:

<elmah>
<security allowRemoteAccess="false" />
<errorLog type="Elmah.MySqlErrorLog, Elmah" connectionStringName="elmah-mysql" />
</elmah>

This required a new connection string... elmah already added the template for me, I just needed to put the correct credentials in:

<connectionStrings>
<add name="DevDB" connectionString="Server=localhost; Database=NZ; Uid=myuserid; Pwd=mypwd" providerName="MySql.Data.MySqlClient"/>
<add name="elmah-mysql" connectionString="Server=localhost; Database=elmah; Uid=myuserid; Pwd=mypwd" providerName="MySql.Data.MySqlClient" />
</connectionStrings>

Make sure EntityFramework provider is correct, if you are using EntityFramework

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>

and DbProviderFactories are correct

<system.data>
<DbProviderFactories>
  <remove invariant="MySql.Data.MySqlClient" />
  <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
  1. Get the relevant SQL Script from here: elmah.Mysql and run the script to create the table and procedures. Also Note that these script by default, create a DB named elmah... if you want to change the db name, make sure it is consistent with your db in the connection string above.

And that's all I had to do to get it running.

Note: One thing to watch for is to use lowercase characters for your DB name, in the above connection string, as MySQL DB names are in lowercase... It did work for me initially with uppercase but then it broke and I had to change it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文