How to make ELMAH log in MySQL?

We integrated ELMAH with ASP.NET MVC 3 as a way to register application errors. However, we still do not save the log. For this purpose, we would like to store ELMAH log entries in MySQL, since we already use an instance of this database server for other purposes.

How to configure ELMAH so that it saves its log with MySQL?

+7
source share
2 answers

You can install the NuGet ELMAH on MySQL package

PM> Install-Package elmah.mysql

You must configure this. from Elmah.MySql.txt, which is part of the package.

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

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

Additional Information

+11
source

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

  • Install Elmah Nuget Package
  • Install Elmah.MySQL Nuget Package

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

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

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

 <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 use 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 appropriate SQL Script from here: elmah.Mysql and run Script to create the table and procedures. Also note that these Scripts by default create a database named elmah ... if you want to change the db name, make sure it matches your db in the connection string above.

And all I had to do to run it.

Note One thing to watch out for is to use lowercase characters for your database name in the connection string above, since DB DB names have lowercase values ​​... It really worked for me with uppercase, but then it broke, and I had to change it.

0
source

All Articles