This commit is contained in:
Ramjot Singh 2018-12-20 12:41:41 -08:00
Родитель 615b1502bb
Коммит b1662aced1
4 изменённых файлов: 24 добавлений и 15 удалений

Просмотреть файл

@ -22,7 +22,7 @@ namespace Microsoft.Extensions.Logging.ApplicationInsights
public bool TrackExceptionsAsExceptionTelemetry { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether the Scope information is excluded from telemetry or not.
/// Gets or sets a value indicating whether the Scope information is included from telemetry or not.
/// Defaults to true.
/// </summary>
public bool IncludeScopes { get; set; } = true;

Просмотреть файл

@ -48,30 +48,30 @@ namespace Microsoft.Extensions.Logging
/// </summary>
/// <param name="builder">The <see cref="ILoggingBuilder"/> to use.</param>
/// <param name="instrumentationKey">Application insights instrumentation key.</param>
/// <param name="configureApplicationInsightsOptions">Action to configure ApplicationInsights logger.</param>
/// <param name="configureApplicationInsightsLoggerOptions">Action to configure ApplicationInsights logger.</param>
/// <returns>Logging builder with Application Insights added to it.</returns>
public static ILoggingBuilder AddApplicationInsights(
this ILoggingBuilder builder,
string instrumentationKey,
Action<ApplicationInsightsLoggerOptions> configureApplicationInsightsOptions)
Action<ApplicationInsightsLoggerOptions> configureApplicationInsightsLoggerOptions)
{
return builder.AddApplicationInsights(
(telemetryConfiguration) => telemetryConfiguration.InstrumentationKey = instrumentationKey,
configureApplicationInsightsOptions);
configureApplicationInsightsLoggerOptions);
}
/// <summary>
/// Adds an ApplicationInsights logger named 'ApplicationInsights' to the factory.
/// </summary>
/// <param name="builder">The <see cref="ILoggingBuilder"/> to use.</param>
/// <param name="configureApplicationInsightsOptions">Action to configure ApplicationInsights logger.</param>
/// <param name="configureApplicationInsightsLoggerOptions">Action to configure ApplicationInsights logger.</param>
public static ILoggingBuilder AddApplicationInsights(
this ILoggingBuilder builder,
Action<ApplicationInsightsLoggerOptions> configureApplicationInsightsOptions)
Action<ApplicationInsightsLoggerOptions> configureApplicationInsightsLoggerOptions)
{
return builder.AddApplicationInsights(
(telemetryConfiguration) => { },
configureApplicationInsightsOptions);
configureApplicationInsightsLoggerOptions);
}
/// <summary>
@ -79,22 +79,22 @@ namespace Microsoft.Extensions.Logging
/// </summary>
/// <param name="builder">The <see cref="ILoggingBuilder"/> to use.</param>
/// <param name="configureTelemetryConfiguration">Action to configure telemetry configuration.</param>
/// <param name="configureApplicationInsightsOptions">Action to configure ApplicationInsights logger.</param>
/// <param name="configureApplicationInsightsLoggerOptions">Action to configure ApplicationInsights logger.</param>
private static ILoggingBuilder AddApplicationInsights(
this ILoggingBuilder builder,
Action<TelemetryConfiguration> configureTelemetryConfiguration,
Action<ApplicationInsightsLoggerOptions> configureApplicationInsightsOptions)
Action<ApplicationInsightsLoggerOptions> configureApplicationInsightsLoggerOptions)
{
if (configureApplicationInsightsOptions == null)
if (configureApplicationInsightsLoggerOptions == null)
{
throw new ArgumentNullException(nameof(configureApplicationInsightsOptions));
throw new ArgumentNullException(nameof(configureApplicationInsightsLoggerOptions));
}
// Initialize IOptions<TelemetryConfiguration> user can keep on configuring it furthur if they want to.
builder.Services.Configure<TelemetryConfiguration>(configureTelemetryConfiguration);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, ApplicationInsightsLoggerProvider>());
builder.Services.Configure(configureApplicationInsightsOptions);
builder.Services.Configure(configureApplicationInsightsLoggerOptions);
return builder;
}

Просмотреть файл

@ -30,8 +30,11 @@
<Description>Application Insights ILogger allows forwarding events from ILogger to Application Insights. Application Insights will collect your logs from multiple sources and provide rich powerful search capabilities. Privacy statement: https://go.microsoft.com/fwlink/?LinkId=512156</Description>
<PackageTags>$(PackageTags) ILogger ILoggerBuilder ILoggerProvider</PackageTags>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup>
<GenerateAdditionalSources>false</GenerateAdditionalSources>

Просмотреть файл

@ -163,6 +163,9 @@ namespace Microsoft.ApplicationInsights
Assert.AreEqual(" => TestScope", (itemsReceived[1] as ISupportProperties).Properties["Scope"]);
Assert.AreEqual("Value", (itemsReceived[1] as ISupportProperties).Properties["Key"]);
Assert.AreEqual("Testing", (itemsReceived[0] as TraceTelemetry).Message);
Assert.AreEqual("Exception", (itemsReceived[1] as ExceptionTelemetry).Message);
}
/// <summary>
@ -171,7 +174,7 @@ namespace Microsoft.ApplicationInsights
/// </summary>
[TestMethod]
[TestCategory("ILogger")]
public void ApplicationInsightsLoggerAddsScopeWhenSwitchIsFalse()
public void ApplicationInsightsLoggerDoesNotAddScopeWhenSwitchIsFalse()
{
List<ITelemetry> itemsReceived = new List<ITelemetry>();
@ -197,6 +200,9 @@ namespace Microsoft.ApplicationInsights
Assert.IsFalse((itemsReceived[1] as ISupportProperties).Properties.ContainsKey("Scope"));
Assert.IsFalse((itemsReceived[1] as ISupportProperties).Properties.ContainsKey("Key"));
Assert.AreEqual("Testing", (itemsReceived[0] as TraceTelemetry).Message);
Assert.AreEqual("Exception", (itemsReceived[1] as ExceptionTelemetry).Message);
}
/// <summary>