1

audit.net.mvc is not creating the json file when an unhandled exception occurs. what do i need to configure?

public class HomeController : Controller
{
    public ActionResult About()
    {
        ViewBag.Message = "Your application description page.";

        var a = 10;
        var b = 0;
        var c = a / b;

        return View();
    }
}

Update: My code configuration

FilterConfig.cs

    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());

            filters.Add(new Audit.Mvc.AuditAttribute()
            {
                IncludeHeaders = true,
                IncludeRequestBody = true,
                EventTypeName = "{verb} {controller}/{action}"
            });
        }
    }

Global.asax

protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Audit.Core.Configuration.Setup()
            .UseFileLogProvider(config => config
                .DirectoryBuilder(_ => $@"C:\temp\Logs\{DateTime.Now:yyyy-MM-dd}")
                .FilenameBuilder(auditEvent => $"{auditEvent.Environment.UserName}_{DateTime.Now.Ticks}.json"));
        }

just remembering that when there is no exception, it works

Thanks

  • Have you read the [documentation](https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.Mvc/README.md)? You have to decorate your Controller/Action with `AuditAttribute` – thepirat000 Feb 23 '20 at 05:47
  • Yes, I registered the filter in the FilterConfig file and configured the provider in the Application_start() event in glabal.asax. But when there is an exception, the audit json is not generated. Only when there is no exception does it generate, regardless of the provider. Debugging the AuditAttribute class, I see that the AuditAction.Exception property is populated. Therefore, I believe that the configuration is correct. – Alexandro Lopes Feb 25 '20 at 23:46
  • You should share the code of your configuration – thepirat000 Feb 26 '20 at 05:36
  • I think the problem is that the scope saving takes place on the `OnResultExecuted` method, but the IResultFilter methods are not called when the action throws an exception. I will work on testing and fix this. Track on issue [#274](https://github.com/thepirat000/Audit.NET/issues/274) – thepirat000 Feb 26 '20 at 18:07
  • updated to 15.0.3 and the issue is resolved. – Alexandro Lopes Feb 26 '20 at 21:32

1 Answers1

2

This was fixed on version 15.0.3 on this commit

Tracked on issue #274

thepirat000
  • 12,362
  • 4
  • 46
  • 72