Coder Social home page Coder Social logo

Comments (9)

thepirat000 avatar thepirat000 commented on June 8, 2024

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.

fjoppe-brunel avatar fjoppe-brunel commented on June 8, 2024

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.

thepirat000 avatar thepirat000 commented on June 8, 2024

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.

fjoppe-brunel avatar fjoppe-brunel commented on June 8, 2024

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.
image

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?

image

from audit.net.

thepirat000 avatar thepirat000 commented on June 8, 2024

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.

fjoppe-brunel avatar fjoppe-brunel commented on June 8, 2024

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 from System.Web.Mvc.Controller, does produce audit logging (nice!);
  • Attribute [AuditApi] does not work on a class inheriting from System.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.

fjoppe-brunel avatar fjoppe-brunel commented on June 8, 2024

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.

thepirat000 avatar thepirat000 commented on June 8, 2024

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.

fjoppe-brunel avatar fjoppe-brunel commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.