Comments (9)
At first sight, your code looks good.
Are you sure that the Audit.Core.Configuration.Setup().UseSerilog()
is ever called?
If for any reason it's not, Audit.NET will be generating .json files as logs in the app folder by default. Do you see any file being created when you call your API action?
from audit.net.
Yes, the UseSerilog() is called - breakpointed it.
Also, if I remove this Serilog initialization, nothing is generated in folder "WebApp/bin".
Note, I am running in Debug mode from Visual Studio.
from audit.net.
What package and version are you referencing for the WebApi audit? Audit.WebApi
or Audit.WebApi.Core
?
You should be referencing Audit.WebApi
.
Can you try to do open Audit.WebApi
let scope = this.GetCurrentAuditScope()
inside your action method to see if the audit scope is being created?
from audit.net.
Hi Frederico,
I only use Audit.WebApi
, I am not using dotnetcore anywhere.
I have inserted the scope assignment you suggested above. Breakpointed it and the Audit.Net scope is returned.
It looks like as everything has been initialized correctly.
I also connected the Debug logger to the Audit logger, and then I got logging in the correct logfile.
Could the issue be because this is an async function?
from audit.net.
Can you share a minimal runnable project that reproduces the issue so I can help further?
I was unable to reproduce and had too little experience with F#.
from audit.net.
I have continued with testing - have not make a repro yet, I'll try this later.
My findings:
- Calling
Audit.Core.AuditScope.Log
in an Api method, produces logging; - Installing package
Audit.Mvc
(21.0.4) and setting the[Audit]
attribute on a class inheriting fromSystem.Web.Mvc.Controller
, does produce audit logging (nice!); - Attribute
[AuditApi]
does not work on a class inheriting fromSystem.Web.Http.ApiController
, nor does the[Audit]
attribute (ok, just tryin :) );
Also, the controllers in the (legacy) code have a multi-layered inheritence scheme as follows:
A
inherits B
inherits System.Web.Mvc.Controller
The [Audit]
tag worked on class B
, while not on class A
.
The [AuditApi]
tag didn't work at all. It appears as if the attribute is not processed.
Another detail that might help is this: the code of all controllers is in a separate class library referenced by the ASP.Net project.
from audit.net.
Unfortunately, I was unable to create a simple project, because the legacy code base is very big, and stripping it just caused other issues. So I took the other approach - get source code of Audit.WebApi
into my solution and temporary use this instead of the nuget package, for investigation.
After setting the attribute and adding a few breakpoints:
Meaning that the attribute works. I've surrounded this line with a try
/catch
all, and it always came into the catch
section.
It always received the exception that binary System.Net.Http.Formatting.dll
version 5.2.6.0 could not be found/loaded. This Stack Overflow response helped me further.
My code was using Microsoft.AspNet.WebApi.Client
version 5.2.7.0, and related libraries too. There also was a version redirection in my Web.Config
, to version 5.2.7.0.
Solution:
After I downgraded every related dependency to "5.2.6.0", including the version redirect, Audit.WebApi is working!
from audit.net.
I'm glad you find a solution.
Wondering if something can be done in the library to avoid this, but I think upgrading the references is not an option for backward compatibility...
from audit.net.
Hi Federico,
The [Audit] tag was working for ASP controllers. So maybe that package could provide a clue.
Perhaps there's a way for strong signed names that allows a version range of an external package.
from audit.net.
Related Issues (20)
- Related object causes multiple audit entries HOT 3
- Question for WebApi: Audit only on statuscodes HOT 2
- Extra Double Quote in PostgreSqlDataProvider Generated SQL HOT 2
- Sometimes when auditing to CosmosDB a CosmosException occurs HOT 5
- Since the new version of mongo-csharp-driver The Jobject for AuditTarget cannot be serialized/deserialized HOT 2
- AuditCommandInterceptor IncludeReaderResults = true results in "DataReader Open" error HOT 9
- Missing Method Exception: Microsoft.EntityFrameworkCore.Metadata.IEntityType.GetProperties() HOT 3
- Best way to "Include" related entity properties HOT 3
- Audit.EntityFramework.Core add support for EF8 Complex Types HOT 1
- Feature Request: New MongoDB interaction extension to audit a MongoDB .NET Driver instance HOT 1
- How to audit entities that have been changed\deleted because of on cascade behavior? HOT 13
- How to ingest data to AzureTableStorage month wise in the AuditTrail implementation using Audit.NET? HOT 2
- Not available to use dbContext in .UseDbContext<MyDbContext> in Audit.Core.Configuration.Setup HOT 6
- Feature Request - Enable configuration of Azure Blob Storage Tags HOT 3
- CosmoDB & EFCore: Storing document per entry instead of per transation. HOT 4
- Logs to ElasticSearch missing full information from version 23.0.0 HOT 3
- Possibility to set and save the AuditEvent from an external source HOT 2
- Store data to common audit table HOT 5
- How to connect AzureTableStorage using UserAssigned ManagedIdentity in the AuditTrail implementation using Audit.NET? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from audit.net.