This article shows how to use PostSharp Logging and Application Insights together.
To use PostSharp Logging with Application Insights:
Add PostSharp Logging to your codebase as described in Getting Started with PostSharp Logging.
Add the
PostSharp.Patterns.Diagnostics.ApplicationInsightspackage to your startup project.Set up your Application Insights resource according to the official guide.
In the application startup method, include the following code before any logged code:
// Configure PostSharp Logging to use Application Insights. LoggingServices.DefaultBackend = new ApplicationInsightsLoggingBackend("YOUR_INSTRUMENTATION_KEY");Note
You can also set the environment variable
APPINSIGHTS_INSTRUMENTATIONKEYor, on .NET Framework, use anApplicationInsights.configfile instead of passing the key to the constructor of ApplicationInsightsLoggingBackend.
See Also
Reference