1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Microsoft] ASP.NETで、PII (personally identifiable information) ログ出力が有効にならない時の対処方法

Posted at

起きたこと

Microsoft.Identity 関係のパッケージを使用しているとき、例外やログに以下のようなメッセージが出力されることがあります。

PII logging is OFF. See https://aka.ms/IdentityModel/PII for details.

プロダクション環境で情報を隠してくれるのはありがたいですが、開発時には困ります。

有効ではない解決策

メッセージに従って https://aka.ms/IdentityModel/PII を見に行くと、以下のようにしろと書いてあります。

IdentityModelEventSource.ShowPII = true;

ではということで、Program.cs にこんなふうに追記しても解決しません。

var builder = WebApplication.CreateBuilder(args);

IdentityModelEventSource.ShowPII = true;

// (snip)

原因

次のクラスの中で、上記プロパティを上書きしています。

LoggingOptions logOptions = new LoggingOptions();
configurationSection?.Bind(logOptions);
IdentityModelEventSource.ShowPII = logOptions.EnablePiiLogging;

正しい解決策

環境変数やappsettings.Development.jsonファイル等で、EnablePiiLogging が true になるようにします。

例えば、このようにします。

appsettings.Development.json
{
  "AzureAd": {
    "EnablePiiLogging": true
  }
}

:exclamation: 注意: AzureAd の部分は、使用するAuthenticationによって変わります。例えばAzureAdB2C等があります。

最後に

解決するまで、GitHub をぐるぐると3時間ほど見て回りました。
やっぱりオープンソースは最高だね!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?