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.

ilogger
Filter by
Sorted by
Tagged with
259 votes
18 answers
242k views

How to unit test with ILogger in ASP.NET Core

This is my controller: public class BlogController : Controller { private IDAO<Blog> _blogDAO; private readonly ILogger<BlogController> _logger; public BlogController(ILogger&...
duc's user avatar
  • 2,737
192 votes
11 answers
191k views

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 ...
reggaemahn's user avatar
  • 6,420
67 votes
5 answers
60k views

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<T> interface from Microsoft.Extensions....
morteng's user avatar
  • 1,242
37 votes
4 answers
57k views

.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&...
OJB1's user avatar
  • 2,525
33 votes
5 answers
70k views

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,...
ˈvɔlə's user avatar
  • 9,661
15 votes
3 answers
8k views

Azure Functions - Injected ILogger<T> 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<T> aren't appearing when I run it in Azure. I've created a ...
Dan's user avatar
  • 5,822
14 votes
2 answers
12k views

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 ...
RonRonDK's user avatar
  • 435
11 votes
3 answers
8k views

How to write logs to EventLog by ILogger<T> 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")) { ...
David Tsui's user avatar
11 votes
2 answers
19k views

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 ...
Tonyc's user avatar
  • 719
9 votes
1 answer
11k views

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 {...
Troskyvs's user avatar
  • 7,787
8 votes
3 answers
4k views

Test ILogger with FakeItEasy

I'm working on a fun project for myself to learn blazor, a lot of core concepts and just general practice. I'm trying to implement logger extension for FakeItEasy to easier test Microsofts ILogger. ...
JochemQuery's user avatar
  • 1,515
8 votes
4 answers
6k views

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 ...
Banshee's user avatar
  • 15.6k
7 votes
2 answers
5k views

Cannot test ILogger<T> Received with NSubstitute

I have a .Net Core 3 application and am trying to test calls to ILogger in my method: public class MyClass { private readonly ILogger<MyClass> _logger; public MyClass(ILogger<...
Shevek's user avatar
  • 3,994
7 votes
2 answers
5k views

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 ...
Reft's user avatar
  • 2,383
6 votes
1 answer
8k views

How to use Microsoft.Extesions.ILogger together with NLog?

I have a system and I want to make a custom logs to create separate folders for each user. Now, I made it in NLog.Logger like a custom file target public static LogFactory ConfigureCustomNLog(string ...
aXe's user avatar
  • 81
6 votes
2 answers
5k views

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 ...
steeee's user avatar
  • 61
6 votes
1 answer
8k views

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 = ...
dimmits's user avatar
  • 2,169
6 votes
2 answers
3k views

ILogger Logging Doesn't Show Up in Azure Application Insights

I'm setting up a new web app to log via Application Insights. I've installed AI, and am seeing all the expected telemetry (server requests, failed requests, etc.) but not logging sent through ILogger. ...
Nat Webb's user avatar
  • 708
6 votes
0 answers
2k views

Reading state values from a ILogger Scope

Is there a way to read/grab 'current scope' values? For example, I've added some 'global context' values in an IPageFilter: // OnPageHandlerExecuting var contextScopeValues = new Dictionary<string,...
Terry's user avatar
  • 2,248
5 votes
4 answers
8k views

Log custom object in Application Insights from Function App ILogger (C#)

I have a C# .NET Core Azure Function App, and I am using the ILogger to send logs to Application Insights. This is working well so far. Function header: public static void Run([TimerTrigger("0 30 ...
Alex's user avatar
  • 149
5 votes
1 answer
2k views

How to use ILogger<Class> 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 ...
nop's user avatar
  • 5,373
5 votes
1 answer
7k views

How to instantiate a logger implementing Microsoft.Extensions.Logging.ILogger<T> that logs to Serilog logger

How do I instantiate a logger implementing Microsoft.Extensions.Logging.ILogger<out TCategoryName> that will output logs to my Serilog logger, when I cannot do it via standard ASP.NET Core ...
Ergwun's user avatar
  • 12.7k
5 votes
1 answer
1k views

C# Azure function ILoggerFactory Not logging with reference library

I created a simple Azure Function using c# and I would like to implement ILoggerFactory for the other class library. Here is my code. MyFunction => Class1 => Class2 namespace FunctionApp1 { ...
user2530833's user avatar
  • 1,017
5 votes
3 answers
2k views

How to mock ILogger.LogXXX methods on netcore 3.0

Until now, we I was mocking the ILogger.LogXXX calls by following this approach. Unfortunately, after updating the project to .net core 3.0, and if you're using strict mocks (Moq), it will always ...
Luis Abreu's user avatar
  • 4,162
5 votes
0 answers
3k views

ILogger - SpanId vs TraceId vs HttpContext.TraceIdentifier

I was running code from this repo and generating an error from the Book.API, I get an error page like this: The request ID is |574e8e13-4e9d31fed64d4793. When I look at the log entry in the file, I ...
Terry's user avatar
  • 2,248
4 votes
2 answers
2k views

Azure Durable orchestration function ILogger outputs logs twice

There are couple of durable functions that call each other. Main orchestration -> Sub orchestration -> Activity -> Helper async method Each func has ILogger dependency and log on function ...
Prog's user avatar
  • 77
4 votes
3 answers
5k views

Creating Base Controller for ASP.NET core to do logging but something is wrong with my constructor signature?

I want to have an easy way to have all the web api controllers automatically log what they are doing without explicitly tell it. Why is this incorrect ? Also, is there any better ways ? public ...
punkouter's user avatar
  • 5,286
4 votes
1 answer
2k views

Can I change the category name given to ILogger<T> instances?

I have a custom ILogger implementation along with an ILoggerProvider and I've noticed that the categoryName parameter in ILoggerProvider.CreateLogger seems to be Type.FullName: Gets the fully ...
Hazel へいぜる's user avatar
4 votes
1 answer
992 views

How to implement an ILogger to send messages to a SignalR Hub?

I want to build a LogView which shows the latest log messages. So I've built a really simple setup but I fail at Dependency Injection. Here's my attempt at an implementation. I've skipped the non-...
heribertJr's user avatar
4 votes
2 answers
6k views

.Net Core Logging Dependency Injection - resolve ILogger / ILogger`1 - what does the tick mean? Resolve type possible?

I'm working with a .Net Core 3.1 XUnit project. I create a SerivceCollection and call the AddLogging extension method. Then I can create an ILogger instance with the LoggerFactory / ILoggerFactory ...
Dudeman3000's user avatar
4 votes
1 answer
3k views

Using Azure Function V3, how do I inject existing Ilogger into new class file?

I have created a new Azure Function, V3, CORE 3.1, using VS2019. It uses a basic HTTPTrigger. I have created a new class file and would like to inject the existing Ilogger into it. How can this be ...
Chris G's user avatar
  • 41
4 votes
1 answer
2k views

Is there a way to log the values from the Data dictionary of an exception in .net core ILogger interface?

If I log an exception with some key/value pairs added to Data, those values do not get logged. They would be really helpful for diagnosis of the issue in some cases but I can't see any way to ...
Simon Vane's user avatar
  • 1,984
3 votes
2 answers
6k views

ILogger Dependency Injection with Azure Functions

So I'm trying to setup ILogger with Dependency Injection and I'm having some trouble. In my startup.cs file I have something that looks like this: builder.Services.AddLogging(); I then try to ...
idude's user avatar
  • 4,794
3 votes
1 answer
5k views

How to provide ILogger<ClassName> instance in new class object from controller in .net core?

As giving null it gives Value cannot be null. (Parameter 'logger') error. Even if instance of model is given it still stays null public class MyController : Controller { public ...
CoderGuy's user avatar
3 votes
1 answer
3k views

What does [40m[32minfo[39m[22m[49m means on DotNetCore logs

I have a DotNet Core application inside a Docker container and when I look into the logs produced by ILogger, I can see those characters: [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc....
Carlos Garcia's user avatar
3 votes
3 answers
5k views

Serilog written to the ILogger does not appear (Azure Functions V2)

I've installed Serilog and configured to write the log event data to a table in MS SQL Server for Azure Function. System logs and logs that have been written by the static class itself appears on the ...
Kadir Ercetin's user avatar
3 votes
1 answer
16k views

Serilog not writing to the file with Configuration loaded from appsettings.json in Console CORE 3 App

ASP.NET CORE 3.1 Worker Service Application. Packages "Microsoft.EntityFrameworkCore.Design" Version="3.1.3" PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.3" ...
Sergey Seriakov's user avatar
3 votes
1 answer
2k views

Minimal API - How to use ILogger in static class

I created the following class: public static class PingEndpoints { public static void Endpoints(this WebApplication application) { var group = application.MapGroup("ping"); ...
Hardipsinh Jadeja's user avatar
3 votes
1 answer
2k views

ApplicationInsights is not considering json configured log level

Given this appsettings.json { "ApplicationInsights": { "InstrumentationKey": "foobar", "LogLevel": { "Default": "Debug" }...
glosrob's user avatar
  • 6,661
3 votes
1 answer
3k views

Debug and Trace logs from Azure Function (.net Core 3.1) not visible in Application Insights

I'm trying to get the Debug and Trace logs to Application Insights via ILogger, but unfortunately it's not going my way. I've made the simplest of demos and I get the INFO, WARN, & ERR logs to ...
Mike's user avatar
  • 155
3 votes
2 answers
3k views

Capture ILogger logs of an asp.net core application on an azure app service

I am working on an asp.net core web application. This application is hosted on an azure app service. This application generates log on standard output (dotnet run command). This log comes from ILogger....
Bob5421's user avatar
  • 8,473
3 votes
1 answer
144 views

Why is ASP.NET ILogger ignoring my log levels?

I am using the ASP.NET ILogger system in a Blazor server app. I instantiate it as follows: using (var loggerFactory = LoggerFactory.Create(loggingBuilder => loggingBuilder ....
David Thielen's user avatar
3 votes
1 answer
6k views

Logger Begin Scope is not working for me! .net Core

So this is my logging configuration: public static void Main(string[] args) { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) ....
Alvaro Mancera Diaz's user avatar
3 votes
0 answers
254 views

Consuming .net standard dll with ILogger in .net framework with nlog

I am working on a dll that is being created in .Net Standard to be consumed by both .net core and .net framework applications. One of the requirements is to have logging within the dll, which can be ...
Gavin Holyday's user avatar
3 votes
2 answers
904 views

ILogger<T>.LogMetric of Azure function is not logging messages into Application Insight

I am using Azure function v3 on .net core 3.x where ILogger<T> is created through dependency injection of respective class T through IServiceProvider like ILogger<T> _log = _log = ...
Riktim Mondal's user avatar
2 votes
1 answer
1k views

What is LoggerExtension Args Parameter and how to integrate with Application insights?

I thought using args parameter i will see a new custom dimension under customDimensions in Azure Application insights but it is not working for me. I cannot find any good information about how to use ...
Emil's user avatar
  • 6,624
2 votes
1 answer
3k views

Implicit scopes for ILogger

I am using ConsoleLoggerProvider from Microsoft.Extensions.Logging (MEL) to write logs in .NET 6 console application. I want my logs to include "class" and "method" records for ...
Maxim V. Pavlov's user avatar
2 votes
2 answers
2k views

Unit Testing Static Methods with ILogger in C# ILoggerFactory is Null

everyone, I'm trying to do unit tests of my code, however I'm not able to get the ILoggerFactory to work This is my unit test code (it may not be correct): using NUnit.Framework; using Microsoft....
Stornu2's user avatar
  • 2,294
2 votes
1 answer
2k views

What is the difference between ApplicationInsights TrackEvent and ILogger LogInformation

If I'm already logging certain "events" via ILogger (_logger.LogInformation), are there any advantages to adding (or changing to) telemetryClient.TrackEvent?
Donny Kwitty's user avatar
2 votes
1 answer
257 views

How can I use ILogger abstractions in a .NET Library with a singleton pattern?

I have a class library that currently uses NLog for its logging purposes. I would like to update this library to use an ILogger<T> abstraction from Microsoft.Extensions.Logging.Abstractions so ...
OpticTygre's user avatar

1
2 3 4 5