2017-07-20 24 views
2

VS2017 15.3.0プレビュー4と.NET Core 2.0プレビュー2をインストールし、既定のWeb MVCアプリケーションを作成しました。私は新しいロギング機能がどのように機能するのか興味がありますが、デバッグ出力ウィンドウを表示するときにappsettings.Development.jsonで定義されたロギング値をVSに使用させることはできません。ASP NETコア2.0 appsettings.Development.jsonがロギング設定で動作しない

私の理解では、appsettings.Development.jsonファイルはappsettings.jsonよりも優先されますが、後者のファイルの値だけがデバッグウィンドウに影響します。これは正しいですか?もしそうなら、追加のセットアップが必要ですか?

ここ

値と結果は...

{ 
    "Logging": { 
    "IncludeScopes": false, 
    "LogLevel": { 
     "Default": "Information", 
     "System": "Information", 
     "Microsoft": "Information" 
    } 
    } 
} 

空の出力デバッグ(ノート

appsettings.json

{ 
    "Logging": { 
    "IncludeScopes": false, 
    "Debug": { 
     "LogLevel": { 
     "Default": "None" 
     } 
    }, 
    "Console": { 
     "LogLevel": { 
     "Default": "Information" 
     } 
    } 
    } 
} 

appsettings.Development.json Application Insightsテレメトリ記録のみが表示されます働いていないVE)まだを取り除くためにどのように

Empty Output

しかし

私はappsettings.jsonでログレベルを変更した場合、私は期待通りの出力を参照してください...

appsettings.json

{ 
    "Logging": { 
    "IncludeScopes": false, 
    "Debug": { 
     "LogLevel": { 
     "Default": "Information" 
     } 
    }, 
    "Console": { 
     "LogLevel": { 
     "Default": "Information" 
     } 
    } 
    } 
} 

新しい出力(Microsoft.AspNetCore.Hosting.Internal.WebHostことに注意してください:情報が含まれるようになりました)デバッグ

enter image description here

マイStartup.csファイルには、以下のとおり、新しいプロジェクトで作成したデフォルトASP.NETコア2.0テンプレートです。また、appsettings.jsonファイルとappsettings.Development.jsonファイルは、新しいプロジェクトテンプレートによって自動的に作成されました。

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?}"); 
     }); 
    } 
} 

ここでは、ASP.NET Core 2.0 MVCテンプレートのデフォルトのProgram.csもあります。

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デフォルトで

DEV "appsettings.Development.json" の設定ファイルは、優先順位を取るため、メインの "appsettings.json" 設定ファイルのdevの設定後にロードされます。しかし、デフォルトのappsettings.Development.jsonファイルには、奇妙に思われるログレベル設定のデバッグノードは含まれていません。ここに作業devの設定です。あなたのappsettings.jsonから

{ 
    "Logging": { 
    "IncludeScopes": false, 
    "LogLevel": { 
     "Default": "None", 
     "System": "None", 
     "Microsoft": "None" 
    }, 
    "Debug": { 
     "LogLevel": { 
     "Default": "Information", 
     "System": "None", 
     "Microsoft": "Information" 
     } 
    } 
    } 
} 
+0

あなたStartup.csは見えない何か好き? – Dealdiane

+0

@Dealdianeスタートアップファイルを追加しました。すべてが新しいASP.NET Core 2.0 MVCテンプレートからの在庫です。私は、json設定ファイル内のログレベルでしか遊んでいません。 – OjM

+0

Program.csも投稿できますか? – Dealdiane

答えて

2

ロガーごとの設定では、あなたのappsettings.Development.jsonからグローバルカテゴリのデフォルト値よりも優先されます。

あなたappsettings.jsonDebugロガーのなしのログレベルを持っているので、あなたは、Visual Studioの出力ウィンドウから任意のログが表示されません。

appsettings.Development.jsonappsettings.jsonのものを上書きするには、.NET Core 2.0(プレビュー2)のログ記録形式を以下の形式にする必要があります。

{ 
    "Logging": { 
    "<Logger>": { 
     "LogLevel": { 
     "Default": "<LogLevel>" 
     } 
    } 
    } 
} 

明確にするデバッグロガー用トレースログレベルを望んでいたならば、これはあなたのJSONの設定でどのように見えるかです:

{ 
    "Logging": { 
    "Debug": { 
     "LogLevel": { 
     "Default": "Trace" 
    } 
} 
関連する問題