Audit.NET | extensible framework to audit executing operations | Model View Controller library
kandi X-RAY | Audit.NET Summary
kandi X-RAY | Audit.NET Summary
An extensible framework to audit executing operations in .NET and .NET Core.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Audit.NET
Audit.NET Key Features
Audit.NET Examples and Code Snippets
Community Discussions
Trending Discussions on Audit.NET
QUESTION
Context
I am trying wireup Audit.Net in an MVC5 app with .Net Framework 4.8.
Dataprovider: EntityFramework
Output: Cosmos
DI Provider: Autofac
The Problem
I have tried the following call backs to try and write the username to the AuditEvent.
...ANSWER
Answered 2021-Oct-08 at 14:00The key (which might help in search terms) is async
. A quick search for async httpcontext mvc
gets us to this existing question with a lot of information about async
/await
and HttpContext
usage.
The super short version: in MVC, the HttpContext
gets carried around in the thread synchronization context (which is also where, say, the culture and other thread settings are carried around) but it's expensive to cart that context from thread to thread so the default is to not do that. You need to enable it explicitly to work.
Here's a blog article explaining the various knobs you can turn in web.config to get it to work but the net result is, basically, to make sure is set (well, set that value to 4.5 or higher).
If that's already set, then... maybe there's something else at play, like a call has the ConfigureAwait(false)
set on it so it's not returning to a thread context that has the HttpContext
. But, more than likely, that httpRuntime
flag should fix it.
QUESTION
First, I installed the Audit Template and created a new project using the Audit.Net template. Using that project as a guide I tried to implement auditing on my actual project where I have an Asp.Net Core API (Project Name: EcommerceAPI
). It also uses Entity Framework Core (in Library Project: Persistence
). I have installed these NuGet packages only to EcommerceAPI:
- Audit.EntityFramework.Core v18.1.3
- Audit.WebApi.Core v18.1.3
Here is my AuditConfiguration.cs
file:
ANSWER
Answered 2021-Aug-26 at 13:07O.K. I had not gone all the way through the docs. This my failure to RTFM.
I needed to install Audit.EntityFramework.Core
on Persistence
and change my DbContext
to AuditDbContext
. It is simple as that.
QUESTION
When using Audit.Net in WebApi a scope is created on every controller action event and when we add custom fields they appear at root level in the json. But when we create audit scope manually and if you add any custom fields to audit scope then they are nested under 'customfields' tag. Not sure why this behaviour is different for both the scope type creation.
See the example below:
This is generated by auditscope created when an action on controller is called:
AuditInfo is added through auditScope.SetCustomField("AuditInfo",auditInfo);
ANSWER
Answered 2021-Aug-09 at 17:48This was fixed on the latest Audit.NET.AzureCosmos
version.
Issue: https://github.com/thepirat000/Audit.NET/issues/434
The problem was because the Audit.NET.AzureCosmos
library previoulsy used Microsoft.Azure.DocumentDB.Core
which was coupled to Newtonsoft.Json
, but Audit.NET
targeting .NET 5.0 uses System.Text.Json
, so the JsonExtensionData
and other attributes required on the AuditEvent
were not taken into account.
Now when targeting .NET Standard 2.0 or .NET 5.0, the new client library Microsoft.Azure.Cosmos
is used, and a custom serializer is set so the serializarion is handled by the default serialization mechanism from Audit.Core.Configuration.JsonAdapter
QUESTION
I'm using Audit.Net for logging all the controller actions in my application and it is an awesome library.
I'm using Azure Cosmos DB to audit all the events. I'm using below setup to connect Cosmos DB:
...ANSWER
Answered 2021-Jul-10 at 00:48A change could be requested here for the Azure Cosmos data provider to allow building the container name with a delegate function that takes the AuditEvent
as a parameter.
Similar to other data providers, like the SQL Server data provider.
So you could setup like this:
QUESTION
I am using Audit.Net library to log EntityFramework actions into a database (currently everything into one AuditEventLogs table, where the JsonData column stores the data in the following Json format:
...ANSWER
Answered 2021-Jun-25 at 17:51Looks like you're asking for an opinion, in that case I would strongly recommend a document oriented DB.
CosmosDB could be a great option since it supports SQL queries.
There is an extension to log to CosmosDB from Audit.NET: Audit.AzureCosmos
A sample query:
QUESTION
I'm getting familiar with audit.net, and finding that the serialization isn't working quite right. I'm wondering if I need to add more configuration. My current config is as follows:
...ANSWER
Answered 2021-Apr-22 at 16:36That's because the middleware can only access the response body already serialized as a byte array, so it's only decoded as string.
On the other hand, the action filter can access the object before it's written to the response stream, so if you also add it to the pipeline, the audit event for the requests reaching an action method, will look like what you're expecting.
For example, on your Startup
class:
QUESTION
When using Audit.Net I'm including entire response to be audited such as response content, headers and IncludeHeaders too, below is my configuration:
...ANSWER
Answered 2021-Mar-12 at 17:26You should use the provided middleware in order to get the response headers, since most of the response headers are added on Result Filters which executes after the Action Filters, and the AuditApiGlobalFilter
is an Action Filter.
The recommended approach is to configure both the action filter and the middleware so you get specific information for the action and also any information added afterwards such as the response headers. Also, including the middleware will allow to audit requests that does not reach a controller/action.
So just add the following to your startup:
QUESTION
I'm using Audit.net for auditing all .net core Web API requests. I want to use global action filter to audit all the HTTP requests but don't want to Audit HTTP GET methods. While configuring AddAuditFilter I can conditionally log action by using LogActionIf filter but unable to set the condition to check whether this action is related to Http Get. Any idea how to add conditional filter? I'm referring to below configuration:
...ANSWER
Answered 2021-Mar-10 at 18:13What about using LogRequestIf
which takes an HttpRequest
as parameter:
QUESTION
I have to update bulk records in a table. I did it as following.
BaseRepository.cs
...ANSWER
Answered 2021-Feb-26 at 20:41You have at least two options
Use the Entity Framework Data ProviderIf you can map the audit log table to an Entity Framework DbContext (it could be the same DbContext you are auditing or a different one), then you could use the EntityFramework Data Provider instead of the SQL Data Provider.
For example, assuming you have an AuditLog table mapped to a DbContext:
QUESTION
I have an ASP.NET Core
application with 2 contexts for 2 databases (context_1 and context_2). I want to audit both contexts ,using Audit.Net
, to separate databases (context_audit_1 and context_audit_2)so I will have 4 databases in total.
The problem is eventhough I am using different contexts in configuration, it is still auditing to one database. In other words, context_1 and context_2 are auditing to context_audit_1.
Please see below the configuration I am using:
Context_1
ANSWER
Answered 2020-Dec-10 at 22:40The problem is that you can't set more than one default data provider to save the events.
So the second time the Audit.Core.Configuration.Setup().UseEntityFramework()
is called, it will override the default data provider previously configured.
But you can use the override of .UseDbContext()
that provides a way to set the Audit DbContext to use on a per-event basis.
So maybe you could have something like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Audit.NET
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page