Search code examples
postsharp

Is the approach for Audit logging in PostSharp 5.x changed?


I see TODO in the link http://doc.postsharp.net/audit

Has there been a change in the way audit log works in 5.x? Or its the same as the article (published in 2011) http://www.postsharp.net/blog/post/5-Ways-That-Postsharp-Can-SOLIDify-Your-Code-Logging-and-Auditing narrates ?


Solution

  • Sorry for the missing doc, we are working on it.

    The custom auditing described in the article still works, but in PostSharp 5.0, we have come with a ready-made auditing aspect as a part of the improved Diagnostics Patterns Library - see https://www.postsharp.net/diagnostics.

    The ready-made auditing pattern works as follows:

    1) Install PostSharp.Patterns.Diagnostics NuGet package to your project.

    2) Add the AuditAttribute custom attribute to all methods you want to be audited.

    3) Register to the AuditServices.RecordPublished event, which would be fired every time an audited method is invoked.

    An example showing this, among others, is available at http://samples.postsharp.net/#PostSharp.Samples.Logging/Program.cs.

    Other resources: