MySQL provider for Audit.NET library (An extensible framework to audit executing operations in .NET).
Store the audit events in a MySQL Table.
NuGet Package To install the package run the following command on the Package Manager Console:
PM> Install-Package Audit.NET.MySql
Please see the Audit.NET Readme
Set the static Audit.Core.Configuration.DataProvider
property to set the MySQL data provider, or call the UseMySql
method on the fluent configuration. This should be done before any AuditScope
creation, i.e. during application startup.
For example:
Audit.Core.Configuration.DataProvider = new MySqlDataProvider()
{
ConnectionString = "Server=localhost; Database=events; Uid=admin; Pwd=admin;",
TableName = "events",
IdColumnName = "event_id",
JsonColumnName = "data",
CustomColumns = new List<CustomColumn>()
{
new CustomColumn("user", ev => ev.Environment.UserName)
}
};
Or by using the fluent configuration API:
Audit.Core.Configuration.Setup()
.UseMySql(config => config
.ConnectionString("Server=localhost; Database=events; Uid=admin; Pwd=admin;")
.TableName("events")
.IdColumnName("event_id")
.JsonColumnName("data")
.CustomColumn("user", ev => ev.Environment.UserName));
- ConnectionString: The MySQL connection string.
- TableName: The table name that stores the audit events.
- IdColumnName: The column name of the event identifier (the primary key column name).
- JsonColumnName: The column name of the event table where the event JSON will be stored. (optional)
- CustomColumn: Additional columns to store information from the audit event. (optional)
This provider implements GetEvent
and GetEventAsync
methods to obtain an audit event by id
var event = mySqlDataProvider.GetEvent(1000);
- The table should exists.
- The table should have a single ID column (Primary key).
For example:
CREATE TABLE event
(
id INT unsigned NOT NULL AUTO_INCREMENT,
inserted_date DATETIME DEFAULT CURRENT_TIMESTAMP,
last_updated_date DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
data JSON NOT NULL,
user VARCHAR(20) NULL,
PRIMARY KEY (id)
);