Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
PR Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym committed May 3, 2017
1 parent 617b4be commit 3d3c311
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCo
services.AddSingleton<IStartupFilter, ApplicationInsightsStartupFilter>();

services.AddSingleton<JavaScriptSnippet>();
services.AddSingleton<ApplicationInsightsLoggerCallbacks>();
services.AddSingleton<ApplicationInsightsLoggerEvents>();

services.AddOptions();
services.AddSingleton<IOptions<TelemetryConfiguration>, TelemetryConfigurationOptions>();
Expand Down Expand Up @@ -277,7 +277,7 @@ internal static void AddTelemetryConfiguration(IConfiguration config, Applicatio

private static bool IsApplicationInsightsAdded(IServiceCollection services)
{
// We treat ApplicationInsightsInitializer as a marker that AI services were addede to service collection
// We treat ApplicationInsightsInitializer as a marker that AI services were added to service collection
return services.Any(service => service.ServiceType == typeof(ApplicationInsightsInitializer));
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Microsoft.ApplicationInsights.AspNetCore.Logging
{
using System;

/// <summary>
/// Class to provide ApplicationInsights logger events
/// </summary>
internal class ApplicationInsightsLoggerEvents
{
/// <summary>
/// Event that is fired when new ApplicationInsights logger is added.
/// </summary>
public event Action LoggerAdded;

/// <summary>
/// Invokes LoggerAdded event.
/// </summary>
public void OnLoggerAdded()
{
LoggerAdded?.Invoke();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static ILoggerFactory AddApplicationInsights(
IServiceProvider serviceProvider,
Func<string, LogLevel, bool> filter)
{
return factory.AddApplicationInsights(serviceProvider, filter, () => { });
return factory.AddApplicationInsights(serviceProvider, filter, null);
}

/// <summary>
Expand All @@ -59,18 +59,24 @@ public static ILoggerFactory AddApplicationInsights(
/// <param name="factory"></param>
/// <param name="filter"></param>
/// <param name="serviceProvider">The instance of <see cref="IServiceProvider"/> to use for service resolution.</param>
/// <param name="loggerAddedCallback">The callback that get's executed when another ApplicationInsights logger is added.</param>
/// <param name="loggerAddedCallback">The callback that gets executed when another ApplicationInsights logger is added.</param>
public static ILoggerFactory AddApplicationInsights(
this ILoggerFactory factory,
IServiceProvider serviceProvider,
Func<string, LogLevel, bool> filter,
Action loggerAddedCallback)
{
var client = serviceProvider.GetService<TelemetryClient>();
if (loggerAddedCallback != null)
var debugLoggerControl = serviceProvider.GetService<ApplicationInsightsLoggerEvents>();

if (debugLoggerControl != null)
{
var debugLoggerControl = serviceProvider.GetService<ApplicationInsightsLoggerCallbacks>();
debugLoggerControl?.AddLoggerCallback(loggerAddedCallback);
debugLoggerControl.OnLoggerAdded();

if (loggerAddedCallback != null)
{
debugLoggerControl.LoggerAdded += loggerAddedCallback;
}
}

factory.AddProvider(new ApplicationInsightsLoggerProvider(client, filter));
Expand Down

0 comments on commit 3d3c311

Please sign in to comment.