![]() This makes it easy to query for events based on those arguments. This is useful because, in addition to passing the formatted message to logging providers, the individual arguments are also made available so that logging providers can record them in a structured format. One useful characteristic of ILogger logging APIs ( LogInformation, LogWarning, etc.) is that they take both a message string and an object of arguments to be formatted into the message. ILogger‘s log APIs send diagnostic messages to the logging providers you have registered. It’s also possible to retrieve an ILoggerFactory and use the CreateLogger method to generate an ILogger with a custom category. This makes it easy to know where events came from when reviewing them later. By convention, ASP.NET Core apps use the class name of the code logging an event as the event’s category. The generic parameter in ILogger will be used as the logger’s category. Once these providers are registered, the application can log to them using an ILogger (retrieved, again, via dependency injection). The AddConsole and AddDebug methods are just extension methods which wrap calls to ILoggerFactory.AddProvider. These methods register logging providers on an instance of the ILoggerFactory interface which is provided to the Startup.Configure method via dependency injection. LoggerFactory.AddConsole(Configuration.GetSection("Logging")) ASP.NET Core new project templates already setup some basic logging providers with this code in the Startup.Configure method: Setting up logging in an ASP.NET Core app doesn’t require much code. It’s also worth mentioning that nothing in requires ASP.NET Core, so these same logging solutions can work in any. There’s already documentation available to help developers get started with ASP.NET Core logging, so I’d like to use this post to highlight how custom log providers (like and Serilog) make it easy to log to a wide variety of destinations. This logging solution (which is used throughout ASP.NET Core, including internally by the Kestrel host) is highly extensible. This guest post was written by Mike RousosĪSP.NET Core supports diagnostic logging through the package.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |