--- lang: ja-jp breaks: true --- # Serilog を使用した UWP C# でのログ出力 2021-04-23 ## 環境 * Windows Server 2019 * Microsoft Visual Studio Professional 2019 Version 16.9.4 * Microsoft.NETCore.UniversalWindowsPlatform 6.2.11 * Serilog 2.10.0 * Serilog.Sinks.File 4.1.0 アプリケーションの最初で静的ログクラスのインスタンスを生成します。 ```csharp= string logFilePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "logs/log.txt"); Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.File(logFilePath, rollingInterval: RollingInterval.Day) .CreateLogger(); Debug.WriteLine("log file:" + logFilePath); ``` あとは、使用したいときに静的ロガーインスタンスを使用して、ログ出力を行います。 ```csharp= Log.Logger.Information("WebView1_PermissionRequested[" + args.PermissionRequest + "]"); ``` ログファイルは、アプリケーションのローカルストアディレクトリに出力されます。 C:\Users\username\AppData\Local\Packages\xxxxxxxxx\LocalState ###### tags: `UWP` `C#` `Serilog` `ログ出力`