Questions tagged [ilogger]

Use this tag for questions about the ILogger interface in the Microsoft.Extensions.Logging namespace, representing a type used to perform logging.

212 questions
244
votes
17 answers

How to unit test with ILogger in ASP.NET Core

This is my controller: public class BlogController : Controller { private IDAO _blogDAO; private readonly ILogger _logger; public BlogController(ILogger logger, IDAO blogDAO) { …
duc
  • 2,585
  • 2
  • 14
  • 14
183
votes
11 answers

Unable to resolve ILogger from Microsoft.Extensions.Logging

I've configured my console application's Main like so var services = new ServiceCollection() .AddLogging(logging => logging.AddConsole()) .BuildServiceProvider(); And then I try to use it in another class like so private readonly ILogger…
reggaemahn
  • 6,272
  • 6
  • 34
  • 59
58
votes
4 answers

Use Serilog with Microsoft.Extensions.Logging.ILogger

I've created a .NET Core 3.1 project using a Host, the IoC container with IServiceCollection and implemented logging allover the place using the ILogger interface from Microsoft.Extensions.Logging. I now need to implement more advanced logging…
morteng
  • 1,133
  • 2
  • 9
  • 22
29
votes
4 answers

How to configure and use Serilog in ASP.NET Core 6?

Since the recently introduced new structure of the Program.cs startup code, the documentation confuses me a bit. In the officially provided Serilog.AspNetCore example and in the Serilog.Sentry example, they use .UseSerilog() on the WebHostBuilder. I…
ˈvɔlə
  • 9,204
  • 10
  • 63
  • 89
28
votes
3 answers

.NET Core 6 - How to get an ILogger instance without Dependency Injection in Program.cs during Startup

I've updated the content of my original question as I was starting to cause some confusion amongst the people trying to help me. I am using the library "Microsoft.ApplicationInsights.AspNetCore" to send logs to Azure. One of the challenges it seems…
OJB1
  • 2,245
  • 5
  • 31
  • 63
13
votes
2 answers

ILogger not writing TRACE and DEBUG messages to target

I'm working on setting up some logging in our ASP.NET Core 3 application, using ILogger (Microsoft.Extensions.Logging) with NLog to enable writing to text files. The problem is, that the ILogger does not write TRACE and DEBUG level messages. Either…
RonRonDK
  • 425
  • 6
  • 22
12
votes
3 answers

Azure Functions - Injected ILogger logs aren't appearing

I'm using FunctionsStartup in an Azure Functions project to setup IoC bindings. However, any logs created from an injected ILogger aren't appearing when I run it in Azure. I've created a very cutdown version with a brand new example project to…
Dan
  • 5,692
  • 3
  • 35
  • 66
11
votes
2 answers

Manage logging configuration with NLog in .NET Core 3

I'm using NLog in a .NET Core 3.1 worker service application. Following the tutorial of NLog I inserted an nlog.config file to manage the configuration. Now I'm confused because I have three points where I configure the logging: In the code where I…
Tonyc
  • 709
  • 1
  • 10
  • 29
10
votes
3 answers

How to write logs to EventLog by ILogger in Asp.net Core?

I follow this document Logging in .NET Core and ASP.NET Core, try to write log to Windows EventLog. first, I create Source and Log in Windows Event Log: if (!EventLog.SourceExists("MyTestSource")) { EventLog.CreateEventSource("MyTestSource",…
David Tsui
  • 433
  • 1
  • 5
  • 8
8
votes
4 answers

Custom Serilog sink with injection?

I have create a simple Serilog sink project that looks like this : namespace MyApp.Cloud.Serilog.MQSink { public class MessageQueueSink: ILogEventSink { private readonly IMQProducer _MQProducerService; public…
Banshee
  • 15,376
  • 38
  • 128
  • 219
7
votes
1 answer

C# ILogger doesn't print console output

I've using vs 2019 for a console application(dotnet core 3.1), Install-Package Microsoft.Extensions.Logging.Console -Version 3.1.2 and this code: using Microsoft.Extensions.Logging; class Program { static void Main(string[] args) { …
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
7
votes
2 answers

Application Insights - ILogger arguments rendered as name of the object in custom dimensions

Objects are rendered as strings, (name of the object), in Application Insights custom dimensions when passed as arguments to ilogger. The actual values are not shown. Register Application Insights services.AddApplicationInsightsTelemetry(); New…
Reft
  • 2,333
  • 5
  • 36
  • 64
6
votes
1 answer

How to Register ILogger(Microsoft.Extensions.Logging) with DI usinq autofac .net framework

I use ILogger from Microsoft.Extensions.Logging in a .net framework project. Now I want to register the ILogger in the container but i cant.All the answers are about .net core. i try var builder = new…
dimmits
  • 1,999
  • 3
  • 12
  • 30
6
votes
2 answers

Mocking and testing the LogError message using Moq and xUnit

I have a class level ILogger which is set up with the ILoggerFactory in the constructor. The logger is then used within a method within that class and this works perfectly. I am struggling on how to Mock the ILogger and ILoggerFactory so I can…
steeee
  • 61
  • 1
  • 2
5
votes
1 answer

How to use ILogger in a Class Library without DI

I have a Class Library and a test integration sample application which uses Serilog. How do I add a logger into the Class Library? I prefer Microsoft.Extensions.Logging, but I cannot find a way to do that without a dependency injection. Sample using…
nop
  • 4,711
  • 6
  • 32
  • 93
1
2 3
14 15