Base solution for your next web application
Open Closed

Enable/disable audit-logging in controllers. #2408


User avatar
0
nach created

Hey, everyone! I've got an issue with enabling/disabling ABP audit-logging in my application module. For example: I've got two controllers and in one of them I want to enable logging and in another - disable.

I tried to do the next in MyWebModule:

[DependsOn(        
        typeof(MyDataModule), 
        typeof(MyApplicationModule), 
        typeof(MyWebApiModule),
        typeof(AbpWebSignalRModule),
        typeof(AbpWebMvcModule))]
    public class MyWebModule : AbpModule
    {
        public override void PreInitialize()
        {
            Configuration.Navigation.Providers.Add<MyNavigationProvider>();      
            // Disabling logging in IApplicationServices
            Configuration.Auditing.Selectors.Clear();
            // Enabling logging in controller that implements IAdminMvcController
            Configuration.Auditing.Selectors.Add(new NamedTypeSelector("Abp.AdminControllers",
                                                                        type => typeof(IAdminMvcController).IsAssignableFrom(type)));
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
// Here I want to enable logging
public class FirstController : MyControllerBase, IAdminMvcController
{
    //...
}

// Here I want to exclude this controller from log
public class SecondController: MyControllerBase
{
   //...
}

When I run this code both controllers are logging actions. How can I disable logging in SecondController?


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can put [DisableAuditing] attribute to your controller, see <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Audit-Logging#DocEnableDisableByAttrs">http://aspnetboilerplate.com/Pages/Docu ... bleByAttrs</a>