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