.net-core-logging

Resolve generic Microsoft.Extensions.Logging.ILogger<T> with Unity - get InvalidCastException

橙三吉。 提交于 2020-06-15 08:28:57
问题 I am trying to register a generic ILogger (from Microsoft.Extensions.Logging, not from Serilog) in Unity (version 4). I've got the following class: public class MyClass { private readonly Microsoft.Extensions.Logging.ILogger<MyClass> _logger; public MyClass(Microsoft.Extensions.Logging.ILogger<MyClass> logger) { _logger = logger; } } And the following Unity registrations and test: // Arrange IUnityContainer container = new UnityContainer(); // provider from Serilog.Extensions.Logging nuget

ILoggerFactory vs serviceCollection.AddLogging vs WebHostBuilder.ConfigureLogging

99封情书 提交于 2019-12-20 09:53:07
问题 I have typical logging requirement for my asp.net core 2.x app: use application insight in production, console and debug logger in development env setup some filters based on category and log level Now I see at least three different API's to configure the logging: WebHostBuilder.ConfigureLogging() in Program.cs public static void Main(string[] args) { var webHost = new WebHostBuilder() .ConfigureLogging((hostingContext, logging) => { logging.AddConfiguration(hostingContext.Configuration

How to enable Trace logging in ASP.NET Core?

元气小坏坏 提交于 2019-12-07 04:26:38
问题 I cannot get basice LogTrace(...) output in my application. Here's a repro: Create a new ASP.NET Core application using Visual Studio 2017. (Optional) comment out .UseApplicationInsights() so the repro is clearer Replace the code in ValuesController.cs with this: using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; namespace WebApplication1.Controllers { [Route("api/[controller]")] public class ValuesController : Controller { private readonly

How to enable Trace logging in ASP.NET Core?

穿精又带淫゛_ 提交于 2019-12-05 09:26:29
I cannot get basice LogTrace(...) output in my application. Here's a repro: Create a new ASP.NET Core application using Visual Studio 2017. (Optional) comment out .UseApplicationInsights() so the repro is clearer Replace the code in ValuesController.cs with this: using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; namespace WebApplication1.Controllers { [Route("api/[controller]")] public class ValuesController : Controller { private readonly ILogger<ValuesController> logger; public ValuesController(ILogger<ValuesController> logger) { this