Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 05:15
    thepirat000 assigned #515
  • 05:14
    thepirat000 commented #516
  • Aug 08 12:18
    sanshep1332 opened #516
  • Aug 08 01:48
    chobo2 opened #515
  • Aug 06 18:26
    thepirat000 closed #514
  • Aug 06 18:26
    thepirat000 commented #514
  • Aug 06 18:25

    thepirat000 on 19.2.1

    (compare)

  • Aug 06 17:58

    thepirat000 on master

    log4net upgrade (compare)

  • Aug 06 17:56

    thepirat000 on master

    changelog (compare)

  • Aug 06 17:54

    thepirat000 on master

    fix: src/Audit.NET.log4net/Audi… (compare)

  • Aug 06 17:54
    thepirat000 closed #511
  • Aug 06 17:53

    thepirat000 on master

    Adding .NET Core support to Aud… (compare)

  • Aug 06 17:48
    thepirat000 edited #514
  • Aug 06 17:47
    thepirat000 opened #514
  • Aug 06 02:53
    thepirat000 closed #512
  • Aug 06 02:53
    thepirat000 locked #512
  • Aug 06 02:45
    chobo2 commented #512
  • Aug 05 23:36
    thepirat000 commented #512
  • Aug 05 23:10
    chobo2 commented #512
  • Aug 05 23:03
    chobo2 commented #512
Federico Daniel Colombo
@thepirat000
about your unit tests, I cannot tell... If you need help with that we'll need the code to reproduce the issue
za8950
@za8950
Thanks for that confirmation
Right now I'm trying to get the AuditInclude attribute working as expected, can you give this a look?
image.png
currently this break point is being hit as I execute my unit test even though I have OptIn() set
and I have no added any [AuditInclude] attribute to my entity classes
my dbcontext simply inherits from AuditDbContext
what am I missing here? I feel its something basic.
Federico Daniel Colombo
@thepirat000
I was unable to reproduce. The event is not firing for me when using OptIn with no AuditInclude attributes
za8950
@za8950
made a few modifications:
  1. Added [AuditInclude] to a partial class file I created to pair with the entity generated object
  2. Added [AuditIgnore] to both AuditLog and AuditLogDetail tables
  3. Update my DbContext File as shown below:
image.png
which follows the implementation from the documentation

now everything works as expected however in the ResolveEntityIdentifiers method, it is only called once even when I have two Audit records being created each with a unique transactionId.

That being said, I can no longer lookup the AuditLog record from the db context since the method only gets hit once and as a result, there is only one transactionId used.

for X number of transactions should there only be one AuditScope that is used?
image.png
when I had the dbcontext setup to inherit from the AuditDBContext, I would end up with that method above getting hit twice, each time a different auditscope with a different transactionId BUT the same entries...
za8950
@za8950
working through the final steps to get this finished...
I found that I have to add the [AuditIgnore] attribute to any domain classes I don't want to be tracked by the AuditCode. Even when setting OptIn() and only adding the [AuditInclude] attribute to the class I wanted to include, ALL classes in the domain context end up triggering the AuditEntityAction when SaveChanges is called.
Am I not doing this right? I would think that simply setting OptIn() would magically exclude any DbContext entities that do not have [AuditInclude] attribute set
Christoffleroux
@Christoffleroux
Hi, is there any library/app that allows the user to query/view the Audit.Net logs
Federico Daniel Colombo
@thepirat000
No there is not, since it will depend on where and how are you storing the logs. Some of the data providers implements a GetEvents / EnumerateEvents for event retrieval
Christoffleroux
@Christoffleroux
Thanks Fedrico
Sebastian
@KP257
Hi there, please could someone assist me with this. I am kinda new to this. I am using Audit.net 19.0.5 and Audit.NET.SqlServer 18.1.6 with .NET 5.0. I am sure this question has been asked in the past. I have read through the Audit.NET.SqlServer information. I want to get a specific value from the JsonData called UserName. Would I need to create my own SqlDataProvider? I tried using CustomFields but got the error
The given key 'UserName' was not present in the dictionary.' So how would I go about adding it to the dictionary? Below is the code I used which I got from a previous question.
Audit.Core.Configuration.Setup()
.UseSqlServer(config => config
.ConnectionString("ConnectionString")
.Schema("dbo")
.TableName("Event")
.IdColumnName("EventId")
.JsonColumnName("JsonData")
.LastUpdatedColumnName("LastUpdatedDate")
.CustomColumn("EventType", ev => ev.EventType)
.CustomColumn("StartDate", ev => ev.StartDate.ToString())
.CustomColumn("EndDate", ev => ev.EndDate.ToString())
.CustomColumn("Duration", ev => ev.Duration.ToString())
.CustomColumn("User", ev => ev.Environment.UserName)
.CustomColumn("UserName", ev => ev.CustomFields["UserName"])
);
Federico Daniel Colombo
@thepirat000
How do you set the UserName custom field? can you share that code?
Also, note you should use the same version for all the Audit.* libraries
alberk8
@alberk8
Is there an example where the DbContext is using EntityFramework Core 7 and I want to log it to mysql provider in another DB, is that possible?
Idris
@gidibloke
I am trying to implement a FallbackSqlDataProvider and i keep getting the error 'The type or namespace name FallbackSqlDataProvider could not be found'. What using statement am i missing or nuget package
Federico Daniel Colombo
@thepirat000
There is no FallbackSqlDataProvider on the library, I guess you are referring to this code https://stackoverflow.com/a/56612862/122195. That's just an example of a custom data provider you can use, but it's not included on a library
paolovalladolid
@paolovalladolid

I am getting this exception
InvalidOperationException: Could not create an instance of type 'Audit.Core.AuditScope'. Model bound complex types must not be abstract or value types and must have a parameterless constructor. Record types must have a single primary constructor. Alternatively, set the 'auditScope' property to a non-null value in the 'POCAuditNet.Pages.ServiceEditModel' constructor.

This is the code for my Razor page, with the CreateAsync method in the OnGetAsync() method. Without the BindProperty tag, I get a NullReference exception in the OnPost() method when auditScope.Save() gets called

public class ServiceEditModel : PageModel
    {
        private readonly IAdminApi repoApi;

        [BindProperty]
        public AuditScope auditScope { get; set; }

        [BindProperty]
        public Service Service { get; set; }

        [TempData]
        public string Message { get; set; }

        public ServiceEditModel(IAdminApi repoApi)
        {
            this.repoApi = repoApi;
        }
        public async Task<IActionResult> OnGetAsync(string serviceId)
        {
            Service = await repoApi.GetService(serviceId);
            auditScope = await AuditScope.CreateAsync(new AuditScopeOptions()
            {
                EventType = "developer-api-portal",
                TargetGetter = () => Service
            });
            return Page();
        }

        public IActionResult OnPost()
        {
            //Auditor.AuditUpdateAsync(Service);
            var updated = repoApi.UpdateService(Service).Result;
            auditScope.Save();
            auditScope.Discard();
            TempData["Message"] = "Service saved!";
            return RedirectToPage("./ServiceOps"); ;
        }

        //public async Task<IActionResult> OnPostAsync()
        //{
        //    Service = await repoApi.UpdateService(Service);
        //    TempData["Message"] = "Service saved!";
        //    return RedirectToPage("./ServiceOps"); ;
        //}
    }
Federico Daniel Colombo
@thepirat000
@paolovalladolid please check my answer on #498
Gerry Hull W1VE/VE1RM/VY1AAA etc...
@w1ve_twitter
I have a dotNet Core 6 Web API application in which we use Audit.Net. We have deployed a version of the app to another server. On our development machines, the Audit trail writes to the auditLog table as expected. On the new machine, it writes the audits to json files in the debug directory, and we have no idea why. Can someone explain? my integrtion is: public static IServiceCollection AddAuditing(this IServiceCollection services)
{
Configuration.Setup()
.UseEntityFramework( =>
.AuditTypeMapper(t => typeof(AuditLog))
.AuditEntityAction<AuditLog>((ev, entry, entity) =>
{
entity.AuditData = entry.ToJson();
entity.EntityType = entry.EntityType.Name;
entity.AuditDate = DateTime.Now;
entity.AuditUser = Environment.UserName;
entity.TablePK = entry.PrimaryKey.First().Value.ToString();
})
.IgnoreMatchedProperties(true));
    return services;
}
Federico Daniel Colombo
@thepirat000
@w1ve_twitter The default data provider stores .json files to the current directory, so it's most likely your AddAuditing method is not being executed before the AuditScope creation
Ovidiu-Daniel Diaconescu
@ovidiu7_gitlab
Hey, does anyone know why do I still get ActionParameters.model although I have IcludeModel = false in the audit attribute?
Federico Daniel Colombo
@thepirat000
If you mean IncludeModelState, that flag only controls ModelStateErrors and ModelStateValid properties
Ovidiu-Daniel Diaconescu
@ovidiu7_gitlab

I actually ended up making the following two things null, not sure if they can be overwritten from the attribute:

var mvcEvent = (AuditEventMvcAction)auditEvent;
mvcEvent.Action.FormVariables = null;
mvcEvent.Action.ActionParameters = null;

hanchoong
@hanchoong
@thepirat000 Hi, is it possible to target the Audit.WCF.Client to .Net 6?
Federico Daniel Colombo
@thepirat000
@hanchoong no it's not
hanchoong
@hanchoong
I addd target framework net6.0 to the WCF.Client project and conditional exclude AuditBehaviour when it is .net 6. Loaded the local package. Works in .net6 but gets the following exception in my original .net framework project.
Could not load file or assembly 'Audit.NET, Version=19.2.0.0, Culture=neutral, PublicKeyToken=793e0c2f32523727' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Any advice how to solve this? Do I have to use all packages built locally?
Federico Daniel Colombo
@thepirat000
Can you share a sample project to take a look?
hanchoong
@hanchoong
chobo2
@chobo2

Hi

Can this library be used to log select statements as well as inserts/updates/deletes?

chobo2
@chobo2
I am trying to setup audit.net with the EF extension but I am not getting any audit tables generated
Federico Daniel Colombo
@thepirat000
@hanchoong nice!!! I'll add the correponding tests and let you know
chobo2
@chobo2
Is it possible via this library or the EF/SQL Extension to add custom columns where the value is only know at runtime. I need to log a userId but it is coming from an http request in the form of a claim.
Federico Daniel Colombo
@thepirat000
@hanchoong I've created the following issue to keep track of the changes thepirat000/Audit.NET#514, this will be added on the next version release
@chobo2 please check the Discussion on github https://github.com/thepirat000/Audit.NET/discussions/513
chobo2
@chobo2
@thepirat000 - yep I see you been helping me out there. Thanks. Just was not sure if other people in this chat might not be actively looking into github discussions but might want to chime in.
hanchoong
@hanchoong
@thepirat000 Great. Thanks.