PostSharp
[Logging]

Add highly detailed logging to your .NET projects with zero impact on source code.

  • Get highly detailed logs with method names, parameters, return values, and execution time.
  • Zero impact on source code. Get started in minutes and keep business logic crystal clear.
  • Completely customizable. Compatible with all logging frameworks.
logging

The highest level of details

Super detailed

You can choose to include the following pieces of data into your logs: doc

  • Method execution and field changes
  • Parameter and return values
  • Execution time
  • Source code file name and line number
  • Awaited method

Adjustable verbosity

You never know what can happen in production. With PostSharp Logging, you can add highly detailed logging to your build but disable it by default.

You can change the verbosity at runtime:

  • For each namespace and type doc
  • For each execution context (such as a web request or transaction) doc

Works on any method

Unlike other technologies, PostSharp Logging lets you instrument all methods, including private or static ones. It can also log changes to fields.

No impact on source code

1
2
3
4
5
6
7
8
9
// Log all public methods of Contoso.BusinessLayer.
[assembly: Log(AttributePriority = 1,
                AttributeTargetTypes = "Contoso.BusinessLayer.*,
                AttributeTargetMemberAttributes = MulticastAttributes.Public)]


// Exclude property getters and setters.
[assembly: Log(AttributePriority = 2,
                AttributeTargetMembers = "regex:(get|set)_.*")]
  • Target thousands of methods with a single line of code based on namespace, name, or visibility. doc
  • Create more complex filters with System.Reflection in C#. doc
  • Remove from release builds with #if DEBUG.

Customizable to your needs

Any logging framework

PostSharp Logging provides out-of-the-box integration with the following .NET logging frameworks. If yours is not listed, it's easy to implement an adapter.

Override anything

Parameter Formatters – Customize how parameter values are rendered, even with external types. doc

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. doc

Custom Logging Framework – You can build an adapter for any VB/C# logging framework, including semantic ones. doc example

Engineered to the demands of modern deployments

Insane performance

We at PostSharp have an obsession for performance. PostSharp Logging is faster than hand-written code in most cases. When logging is disabled, there is no performance impact at all. doc

Robustness

Things break. You know. But we don't want your mission-critical to go down just because logging does not work. We've implemented an aggressive circuit breaker so that when any failure happens, logging is immediately disabled. doc

Privacy & security aware

Prevent passwords and confidential data to leak to logs thanks to the [NotLogged] attribute. doc

Semantic logging

When using a semantic logging framework and log server such as Serilog with ElasticSearch, PostSharp Logging separates message templates from variable parameters, so you can easily search, filter and bucketize log records. doc

Distributed logging

PostSharp Logging supports the key concepts of distributed logging: activities (also named scopes or traces), baggage, and synthetic ids. doc

Sampled logging

Instead of generating tens of GBs by logging all requests, you can choose to capture only a random sample of them. doc

No agent needed

PostSharp Logging instruments your code at build time. You don't need to install anything on end-user devices. It works on desktop, mobile and server devices.

No monthly or per-GB costs

Bring your own storage. PostSharp Logging will store your data where you want.