Faster than hand-written code – Code instrumented with PostSharp is typically faster than code instrumented by hand. We've benchmarked.
Enable/disable at run time – Logging can be turned on and off dynamically at run time using a simple API. When logging is disabled, the cost overhead is as low as 0 thanks to the JIT compiler optimizations.
GC-friendly – PostSharp does not allocate memory unless your logging framework requires it. For instance, with ETW, striclty no managed memory is allocated.
// Log all public methods of the Contoso.BusinessLayer namespace. [assembly: Log(AttributePriority = 1, AttributeTargetTypes = "Contoso.BusinessLayer.*" AttributeTargetMemberAttributes = MulticastAttributes.Protected | MulticastAttributes.Internal | MulticastAttributes.Public)] // Exclude property getters. [assembly: Log(AttributePriority = 2, AttributeExclude = true, AttributeTargetMembers = "get_*" )] // In DEBUG build, add logging to the registry API. #if DEBUG [assembly: Log( AttributePriority = 3, AttributeTargetAssemblies = "mscorlib" AttributeTargetTypes = "Microsoft.Win32.Registry*" )] #endif
You can choose to include the following pieces of data into your logs:
Parameter Formatters – Customize how parameter values are rendered, even with external types.
Enable/Disable Features – Most features can be enabled or disabled manually so you only get what you actually need. Don't need parameter names? No problem.
Override Anything – You can replace almost any formatting logic with your own.
Custom Logging Framework – You can build an adapter for any logging framework, including semantic ones.
PostSharp provides out-of-the-box integration with the following products: