I have installed VS2017 15.3.0 Preview 4 and .NET Core 2.0 Preview 2 and have created a default Web MVC application. I am interested in seeing how the new logging functionality works but I cannot get VS to use the logging values defined in appsettings.Development.json when viewing the Debug output window.
My understanding is that the appsettings.Development.json file takes precedence over the appsettings.json yet only values in the latter file has any effect on the debug window. Is this right? If so is there additional setup required?
Here are the values and results...
appsettings.json
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "None"
}
},
"Console": {
"LogLevel": {
"Default": "Information"
}
}
}
}
appsettings.Development.json
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
}
}
}
Empty output when debugging (note only Application Insights Telemetry records are shown which I have not worked out how to get rid of yet)
However if I change the log levels in appsettings.json then I see the output as expected...
appsettings.json
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Information"
}
},
"Console": {
"LogLevel": {
"Default": "Information"
}
}
}
}
New Output when debugging (note that Microsoft.AspNetCore.Hosting.Internal.WebHost:Information is now included)
My Startup.cs file is the default ASP.NET Core 2.0 template created with the new project as per below. Also both the appsettings.json and appsettings.Development.json files were automatically created by the new project template too.
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
Here is my Program.cs which is also the default for an ASP.NET Core 2.0 MVC template.
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
SOLUTION
By default the dev "appsettings.Development.json" config file is loaded after the main "appsettings.json" config file therefore dev configuration taking priority. However the default appsettings.Development.json file does not include the Debug node for log level settings which seems strange. Here is the working dev config.
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "None",
"System": "None",
"Microsoft": "None"
},
"Debug": {
"LogLevel": {
"Default": "Information",
"System": "None",
"Microsoft": "Information"
}
}
}
}