EdwardPage
EdwardPage

Reputation: 11

Audit logging methods within methods in Asp.NET Boilerplate

I've been working on ASP.NET BoilerPlate project, where I expect to make the audit logging more detailed.

So I got a method, that is calling different other methods, but in audit logging it show just the first level method that is called.

For example:

public class AuditLogAppService : TestAppServiceBase, IAuditLogAppService
{

...

public async Task<FileDto> GetTestInputToFile(GetTestInput input)
    {
        TestAuditInterception();

        ...

        return testExporter.ExportToFile(testDtos);
    }
}

It does audit log the GetTestInputToFile method, but it doesn't log TestAuditInterception().

As I've read the documentation, it says:

A method must be public in order to saving audit logs. Private and protected methods are ignored. I'm not sure if this is my case, though.

Is there a way to log the method within the logged method (TestAuditInterception())?

Upvotes: 0

Views: 570

Answers (1)

hikalkan
hikalkan

Reputation: 2282

I suppose this service is exposed as API Controller. I also assume that this is an ASP.NET Core application (not MVC 5.x).

In that case, no built-in way of doing that. Only, the entrance method is logged. This is by design.

In most cases, this is a good behavior for audit logging, because the client (or user) calls a public method, then the method may call another private methods. No need to log the entire call stack. Only entrance points should be logged.

In addition, we don't suggest to call a public application service method from another one, as a good practice. If you want to reuse a code, move the common part to a private method.

If you still want that, you can create an issue on the Github (https://github.com/aspnetboilerplate/aspnetboilerplate/issues/new), so we consider it for the next versions.

Upvotes: 1

Related Questions