1

I was trying to use application Insights as my logging backend from postsharp references. I have setup the application insights and was able to see live metrics. But I am not quite sure if postsharp logging alone is able to write to application insights.

My code in Program.cs

using PostSharp.Patterns.Diagnostics;

using PostSharp.Patterns.Diagnostics.Backends.ApplicationInsights;

LoggingServices.DefaultBackend = new ApplicationInsightsLoggingBackend("InstrumentationKey");

GlobalAspects.cs file:

using PostSharp.Patterns.Diagnostics;

using PostSharp.Extensibility;

// This file contains registration of aspects that are applied to several classes of this project.

[assembly: Log(AttributeTargetTypeAttributes=MulticastAttributes.Public, AttributeTargetMemberAttributes=MulticastAttributes.Public)]

Do I need to setup anyhting in my program.cs in order to completely make use of postsharp logging to write to applicationinsights.

1 Answers1

0

You need to set the default verbosity of the Application Insights logging backend to Trace to get the method call log records.

LoggingServices.DefaultBackend.DefaultVerbosity.SetMinimalLevel(LogLevel.Trace);
Antonín Procházka
  • 1,388
  • 8
  • 16
  • Thankyou. Can I filter out only certain logs? I don't want to log everything like validation messages or anything like that. Like What if I wanted to log only exceptions and errors? @AntoninProchazka – user15368519 Mar 11 '21 at 14:06
  • Is there any kind of reference on github or elsewhere for a complete only Postsharp Logging (without serilog) using only ApplicationInsights as backendsink that logs exceptions and information messages.#Postsharp – user15368519 Mar 11 '21 at 17:22
  • There are several options: 1) Set the log level to Info. (https://doc.postsharp.net/t_postsharp_patterns_diagnostics_loglevel) 2) Make the LogAttribute multicast more specific. (https://doc.postsharp.net/multicast-conceptual) 3) Use different logging profiles. (https://doc.postsharp.net/logging-customizing#buildtime) – Antonín Procházka Mar 12 '21 at 09:15
  • There's no such example now, but for better understanding, the ApplicationInsightsLoggingBackend passes all log records to Application Insights as TraceTelemetry. (https://learn.microsoft.com/en-us/dotnet/api/microsoft.applicationinsights.datacontracts.tracetelemetry?view=azure-dotnet) – Antonín Procházka Mar 12 '21 at 09:43