Remove default AI logger settings (#69)
This commit is contained in:
parent
4dba368c8a
commit
b484d2ee4f
|
|
@ -22,5 +22,8 @@
|
||||||
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
|
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
|
||||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
|
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="appsettings.json" CopyToOutputDirectory="PreserveNewest" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -73,20 +73,21 @@ namespace IISSample
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var config = new ConfigurationBuilder()
|
|
||||||
.AddCommandLine(args)
|
|
||||||
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
var host = new WebHostBuilder()
|
var host = new WebHostBuilder()
|
||||||
|
.ConfigureAppConfiguration((hostingContext, config) =>
|
||||||
|
{
|
||||||
|
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
||||||
|
config.AddCommandLine(args);
|
||||||
|
})
|
||||||
.ConfigureLogging((hostingContext, builder) =>
|
.ConfigureLogging((hostingContext, builder) =>
|
||||||
{
|
{
|
||||||
|
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
||||||
builder.AddConsole();
|
builder.AddConsole();
|
||||||
})
|
})
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
.UseConfiguration(config)
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
host.Run();
|
host.Run();
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,10 @@
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"IncludeScopes": false,
|
"IncludeScopes": false,
|
||||||
"Debug": {
|
"LogLevel": {
|
||||||
"LogLevel": {
|
"Default": "Information",
|
||||||
"Default": "Warning"
|
"System": "Warning",
|
||||||
}
|
"Microsoft": "Warning"
|
||||||
},
|
|
||||||
"Console": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Warning"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,11 @@ namespace Microsoft.AspNetCore.ApplicationInsights.HostingStartup
|
||||||
|
|
||||||
// We need to disable filtering on logger, filtering would be done by LoggerFactory
|
// We need to disable filtering on logger, filtering would be done by LoggerFactory
|
||||||
var loggerEnabled = true;
|
var loggerEnabled = true;
|
||||||
Action disableCallback = () => loggerEnabled = false;
|
|
||||||
|
|
||||||
// We detected that logger settings got to LoggerFactory configuration and
|
|
||||||
// defaults would be applied
|
|
||||||
loggerFactory.AddApplicationInsights(
|
loggerFactory.AddApplicationInsights(
|
||||||
builder.ApplicationServices,
|
builder.ApplicationServices,
|
||||||
(s, level) => loggerEnabled,
|
(s, level) => loggerEnabled,
|
||||||
disableCallback);
|
() => loggerEnabled = false);
|
||||||
|
|
||||||
next(builder);
|
next(builder);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ namespace Microsoft.AspNetCore.ApplicationInsights.HostingStartup
|
||||||
/// <param name="services">The <see cref="IServiceCollection"/> associated with the application.</param>
|
/// <param name="services">The <see cref="IServiceCollection"/> associated with the application.</param>
|
||||||
private void InitializeServices(IServiceCollection services)
|
private void InitializeServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<IConfigureOptions<LoggerFilterOptions>, DefaultApplicationInsightsLoggerFilters>();
|
|
||||||
services.AddSingleton<IStartupFilter, ApplicationInsightsLoggerStartupFilter>();
|
services.AddSingleton<IStartupFilter, ApplicationInsightsLoggerStartupFilter>();
|
||||||
services.AddSingleton<ITagHelperComponent, JavaScriptSnippetTagHelperComponent>();
|
services.AddSingleton<ITagHelperComponent, JavaScriptSnippetTagHelperComponent>();
|
||||||
|
|
||||||
|
|
@ -59,28 +58,4 @@ namespace Microsoft.AspNetCore.ApplicationInsights.HostingStartup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class DefaultApplicationInsightsLoggerFilters : IConfigureOptions<LoggerFilterOptions>
|
|
||||||
{
|
|
||||||
private const string ApplicationInsightsLoggerFactory = "Microsoft.ApplicationInsights.AspNetCore.Logging.ApplicationInsightsLoggerProvider";
|
|
||||||
|
|
||||||
private static readonly KeyValuePair<string, LogLevel>[] _defaultLoggingLevels = {
|
|
||||||
new KeyValuePair<string, LogLevel>("Microsoft", LogLevel.Warning),
|
|
||||||
new KeyValuePair<string, LogLevel>("System", LogLevel.Warning),
|
|
||||||
new KeyValuePair<string, LogLevel>(null, LogLevel.Information)
|
|
||||||
};
|
|
||||||
|
|
||||||
public void Configure(LoggerFilterOptions options)
|
|
||||||
{
|
|
||||||
foreach (var pair in _defaultLoggingLevels)
|
|
||||||
{
|
|
||||||
options.Rules.Add(new LoggerFilterRule(
|
|
||||||
ApplicationInsightsLoggerFactory,
|
|
||||||
pair.Key,
|
|
||||||
null,
|
|
||||||
(type, name, level) => Debugger.IsAttached || level >= pair.Value
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue