Plinth NLog Target for Application Insights
$ dotnet add package Plinth.Logging.NLog.AppInsightsIntegration allowing Plinth and NLog to record telemetry and logs to Azure Application Insights
<nlog> tag <extensions>
<add assembly="Plinth.Logging.NLog.AppInsights" prefix="plinthAI" />
</extensions>
<targets>
<target xsi:type="plinthAI.AppInsightsTarget" name="aiTarget">
<connectionString>{from-Azure-Portal}</connectionString>
<cloudRoleName>testRole1</cloudRoleName>
<cloudRoleInstance>serverA</cloudRoleInstance>
<maxLength>25000</maxLength>
</target>
</targets>
cloudRoleName and cloudRoleInstance are optional, and will have reasonable defaults if not specifiedmaxLength field is optional, and defaults to 25000 characters<instrumentationKey> is supported but deprecated and will stop working in March 2025 <rules>
<logger name="*" minlevel="Debug" writeTo="aiTarget" />
</rules>
services.AddPlinthAppInsightsTelemetry(cfg =>
{
cfg.CloudRoleName = "MyApp";
cfg.DisabledPrefixes.Add("/health");
});
:point_right: The lambda is optional and only necessary if setting hardcoded configuration
Configurations Options are
ConnectionString: If not setting via environment variable or NLog.configDisabledPrefixes: A blacklist of url prefixes to disable Request Telemetry. Example: "/favicon.ico"EnabledPrefixes: A whitelist of url prefixes to enable Request Telemetry. This is null by default. If a list of prefixes is specified, only requests which match will have request telemetry. If there is a conflict between this and DisabledPrefixes, the preference is to disable telemetry.CaptureSqlCommandText: Set to true to have SQL Dependency Telemetry capture the SQL command text sent to the database. Defaults to false.CloudRoleName: See next sectionCloudRoleInstance: See next sectionValues are applied in this order of precedence
Connection String (get this from the Azure Portal)
<connectionString>APPLICATIONINSIGHTS_CONNECTION_STRINGCloud Role Name
<cloudRoleName>APPLICATIONINSIGHTS_CLOUD_ROLENAMECloud Role Instance
<cloudRoleInstance>APPLICATIONINSIGHTS_CLOUD_ROLEINSTANCE