---
# System prepended metadata

title: gRPC `ASP.NET Core` ログ出力 2021-09-18
tags: [gRPC, ASP.NET Core, ログ出力]

---

---
lang: ja-jp
breaks: true
---
# gRPC `ASP.NET Core` ログ出力 2021-09-18

## サーバ側 `Program.cs`

```csharp=
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureLogging(logging =>
                {
                    logging.SetMinimumLevel(LogLevel.Trace);
                    logging.AddFilter("Microsoft", LogLevel.Trace);
                    logging.AddFilter("Grpc", LogLevel.Trace);
                }).ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
```

## クライアント側

```csharp=
Install-Package Microsoft.Extensions.Logging
Install-Package Microsoft.Extensions.Logging.Console
```

```csharp=
var loggerFactory = LoggerFactory.Create(logging =>
{
    logging.AddConsole();
    logging.SetMinimumLevel(LogLevel.Trace);
});
var canelOptions = new GrpcChannelOptions
{
    LoggerFactory = loggerFactory
};
GrpcChannel channel = GrpcChannel.ForAddress(url, canelOptions);
```

###### tags: `gRPC` `ASP.NET Core` `ログ出力`
