Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure ASP.NET audit log

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to configure ASP.NET audit logs". In daily operation, I believe many people have doubts about how to configure ASP.NET audit logs. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to configure ASP.NET audit logs". Next, please follow the editor to study!

An audit trail (also known as an audit log) is a security-related chronological record that is intended to provide supporting document records, sources, or events that have affected detailed operations at any time.

ABP provides an infrastructure that automatically logs application interactions, recording the caller information and parameter information of the method you call. Fundamentally, the storage area contains:

Tenant id (related tenant Id)

User id (request user Id)

Server name (name of the requested service [class corresponding to the calling method])

Method name (calling method name)

Parameters (parameters of the method [JSON format])

Execution time (execution time)

Duration (execution time [usually milliseconds])

IP address (client IP address)

Computer name (client name)

Information such as exception (if the method throws an exception).

With this information, we can not only know who did the operation, but also estimate the performance of the application and the exceptions thrown. Even more, you can get statistics about the usage of the application.

The audit system uses the IAbpSession interface to get the current user Id and tenant ID.

Note: about the IAuditingStore interface

The audit system uses the IAuditingStore interface to save audit information. The module-zero project is a complete implementation of this interface, but you can also implement it in your own way. If you don't want to implement this interface yourself, the SimpleLogAuditingStore class can be used directly by writing audit information to the log.

Configuration

Audit can be configured using the Configuration.Auditing property in your module initialization method (PreInitialize). The Auditing attribute is enabled by default (that is, true). You can disable it, as shown in the following figure:

Public class MyModule: AbpModule

{

Public override void PreInitialize ()

{

Configuration.Auditing.IsEnabled = false

}

/ /...

}

The following are the properties of the audit configuration:

IsEnabled: used to set the audit system to be fully enabled or disabled. Default value: true.

IsEnabledForAnonymousUsers: if set to ture, the audit logs of non-logged-in users will also be saved. Default value: false.

MvcControllers: using audit logs in the ASP.NET MVC controller

IsEnabled: enable (true) or disable (false) audit logs in ASP.NET MVC. Default value: true.

IsEnabledForChildActions: enable (true) or disable (false) audit logs for MVC actions. Default value: false.

Selectors: choose to use other classes to handle the storage of audit logs.

As you can see, the audit system separately provides an audit configuration for the mvc controller so that it can be used in different ways.

Selectors is a list of assertion (inference type) selectors to choose which way to save the audit log. Each selector contains a unique name and an assertion. The default selector in the assertion list uses the application service class. As shown in the following figure:

Configuration.Auditing.Selectors.Add (

New NamedTypeSelector (

"Abp.ApplicationServices"

Type = > typeof (IApplicationService) .IsAssignableFrom (type)

)

);

You can add your own assertion selector to your module initialization method (PreInitialize). Similarly, if you don't like using the application service to save audit logs, you can also remove the assertion selector by name (name), which is why the name of the assertion selector must be unique (you can also find the selector through Linq to remove it).

Enable and disable audit logs through properties

When you use configuration items to configure the assertion selector, you can enable and disable the audit system by marking it to a single class or method using the Audited and DisableAuditing features. For example:

[Audited]

Public class MyClass

{

Public void MyMethod1 (int a)

{

/ /...

}

[DisableAuditing]

Public void MyMethod2 (string b)

{

/ /...

}

Public void MyMethod3 (int a, int b)

{

/ /...

}

}

In the above column, all methods in the MyClass class are audited except that MyMethod2 explicitly indicates that they do not require auditing. The Audited feature can help you save audit logs in ways that only want to save audit logs.

Description

The method to save the audit log must be public-decorated, and the private and protected-decorated methods will be ignored. If the called method is not within the scope of the class reference, the referenced method must be a virtual method (virtual), and if the dependency injection is its own interface, it does not need to be a virtual method (for example, injecting IPersonService to use the PersonService class).

After ABP uses dynamic proxies and interception mechanisms, it is necessary to use virtual methods. Using audit logs for MVC Controller actions is not the right thing to do because they may not be virtual methods.

At this point, the study on "how to configure ASP.NET audit logs" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report