Questions tagged [microsoft.extensions.logging]
28 questions
13
votes
1 answer
Is it better to use Serilog with or without Microsoft.Extensions.Logging?
I'm building an API using .NET 6 and plan to use Serilog as logger. According to https://onloupe.com/blog/serilog-vs-mel/ there are two possibilities:
Use Serilog exclusively
Use Microsoft.Extensions.Logging as logging API + Serilog as logging…

dario
- 2,861
- 3
- 15
- 34
4
votes
3 answers
Get ScopeContext properties in AsyncTaskTarget
I am implementing a custom NLog AsyncTaskTarget, and I need to retrieve values that I have added using Microsoft.Extensions.Logging.ILogger.BeginScope:
using (var scope = logger.BeginScope(new []
{
new KeyValuePair("userId",…

marsze
- 15,079
- 5
- 45
- 61
4
votes
0 answers
.net5.0 PRISM WPF application, how to use Microsoft.Exensions.Logging with Serilog as provider?
I've got a PRISM (8.1.97) WPF application running on .net5.0 with the unity container.
What I would like to do is to assign Serilog as my logging provider, but inject the usual Microsoft.Extensions.Logging logger through the constructor of my DI…

Angelo
- 2,936
- 5
- 29
- 44
4
votes
1 answer
TraceId, RequestId, and TraceIdentifier in ASP.NET Core
I'm wondering how ASP.NET Core and Microsoft.Extensions.Logging assigns TraceId, RequestId, and TraceIdentifier. When looking through my log after making a request to my website I see the following information logged from…

ThomasArdal
- 4,999
- 4
- 33
- 73
3
votes
0 answers
Does ASP .NET Core logging API have method to create independent loggers similar to Serilog "ForContext" method?
How it works in Serilog
Every ILogger in Serilog has useful method ForContext which essentially creates completely independent child logger with some properties attached.
This is useful for my case, when inside one ASP .NET Core host there are N…

ArXen42
- 139
- 1
- 8
3
votes
1 answer
How to check current log level using ILogger?
I am using Microsoft.Extensions.Logging.ILogger. I want to log request object only when LogLevel is set to Information
I know I can log the request object as
_logger.LogInformation("{request}", request);
I am using Serilog as logger. This…

LP13
- 30,567
- 53
- 217
- 400
3
votes
1 answer
System.Exception: Method not found: 'ILoggerFactory.AddConsole(Microsoft.Extensions.Logging.ILoggerFactory, Microsoft.Extensions.Logging.LogLevel)'
I am trying to upgrade the .netcore framework from 2.2 to 3.1 .
But I want to use IHostingEnvironment, IWebHostBuilder and AddNewtonsoftJson in 3.1 also.
(I know they should be replaced but if I will do so, code refactoring will be required, which i…

kamini kumari
- 31
- 5
3
votes
1 answer
MS Extensions Logging "LogError" method is throwing exception "Index (zero based) must be greater than or equal to zero"?
"Microsoft.Extensions.Logging.LoggerExtensions.LogError" is throwing exception
Index (zero based) must be greater than or equal to zero and less than
the size of the argument list.
Code:
string SomeConstant = "Constant Value";
try
{
//Some…

Shreyansh Deb
- 53
- 1
- 1
- 6
2
votes
0 answers
Microsoft.Extensions.Logging and Serilog logger configurations
In my WPF .netCore 5 app, I'm using three libraries where each library accepts Microsoft.Extensions.Logging.ILogger at initialization. I'm using Serilog and ILoggerFactory. I create three LoggerConfigurations with different WriteTo.File…

zmuro
- 21
- 3
2
votes
0 answers
Preventing Log Category from being logged in Microsoft.Extensions.Logging SimpleConsole logs
I have added logging to two projects (.net-5 and .net-6) using Microsoft.Extensions.Logging SimpleConsole as below:
services.AddLogging(builder => builder
.AddSimpleConsole(options =>
…

trajekolus
- 535
- 6
- 16
1
vote
0 answers
Microsoft.Extensions.Logging.ILogger - Custom formatting of logging properties
Without creating a brand new customer ILogger type, is it possible to somehow register "formatters" for different parameter types?
Example:
double someVar = 10.3;
/*snip*/
logger.LogDebug("Look at this property {MyProp}", someVar);
Can I somehow…

Roger Johansson
- 22,764
- 18
- 97
- 193
1
vote
0 answers
Any way for long living log scopes in .NET
I have the need to add information to the log scopes in .NET and they need to survive longer than a single method call...
Usualy the samples always tell us to use log scopes like this
public void DoSomething()
{
…

monty
- 7,888
- 16
- 63
- 100
1
vote
1 answer
Microsoft.Extensions.Logging - Add multiple windows event logs
I have a .NET Core application, writing to Windows event viewer.
I'd like to map some of the logs to one source and some to other (based on the caller class).
The setup in Program.cs looks like that:
public static IHostBuilder…

noamyg
- 2,747
- 1
- 23
- 44
1
vote
1 answer
MissingMethodException: No parameterless constructor defined for type
I have a Blazor app using .net core 5. I am trying to run a page to trigger an email send (EmailSample) which works fine until I try to add a constructor injection for logging errors. as soon as I add the constructor injection and rerun the page I…

D Smith
- 13
- 4
1
vote
1 answer
How to use Microsoft.Extensions.Logging.Abstraction 5.0.0 with Azure Durable Functions
I am working with Azure Functions and I am having a problem that involves the NuGet "Microsoft.Extensions.Logging.Abstractions". My solution has been running perfectly fine, but recently I added a dependency which depends on…

Alonso Montero
- 138
- 1
- 8