Replies: 1 comment
-
There is no WPF extension and I'm affraid it will never be one, since there is no way to easily hook into all the events in a WPF application, unless some reflection/emit tricks are used, but even so it will really impact the performance of the application and not be helpful. But maybe I'm missing something. Anyway you can use the Audit.NET core framework to manually create your audit events. For example you can configure the audit SQL data provider in your App static constructor: public partial class App : Application
{
static App()
{
Audit.Core.Configuration.Setup()
.UseSqlServer(sql => sql
.ConnectionString("...")
.TableName(ev => "AuditEvent")
.IdColumnName(ev => "EventId")
.JsonColumnName(ev => "Data")
.LastUpdatedColumnName("LastUpdatedDate")
.CustomColumn("EventType", ev => ev.EventType));
}
} And suppose you have a click event you want to audit: private void SaveButton_Click(object sender, RoutedEventArgs e)
{
var id = txtBoxId.Text;
var newValue = txtBoxValue.Text;
UpdateValue(id, newValue);
} You can just surround the code within an AuditScope like this: private void SaveButton_Click(object sender, RoutedEventArgs e)
{
var id = txtBoxId.Text;
var newValue = txtBoxValue.Text;
using (var scope = AuditScope.Create("Save Operation", null, new { id, newValue }))
{
var result = UpdateValue(id, newValue);
scope.SetCustomField("result", result);
}
} And you'll end up having audit logs like this (JSON representation): {
"EventType": "Save Operation",
"Environment": {
"UserName": "Federico Colombo",
"MachineName": "...",
"DomainName": "..."
},
"StartDate": "2023-03-07T06:41:31.3515671Z",
"EndDate": "2023-03-07T06:41:32.3541883Z",
"Duration": 1003,
"id": "123",
"newValue": "NEW",
"result": true
} Even if an exception is thrown by the |
Beta Was this translation helpful? Give feedback.
-
Hello
Is it possible to use the Audit.net library in a WPF application?
If possible, can you give me an example. I am interested in saving all changes in one table in MSSql database. I've read the tutorial but I don't really know where to put e.g. configuration in the WPF application.
Beta Was this translation helpful? Give feedback.
All reactions