ilogger

Output JSON in Azure Function Logs

匆匆过客 提交于 2020-07-23 06:32:26
问题 We'd like to send structured log data from our Azure Functions to Event Hub. So I set up Serilog to log to the console and include all the info I wanted. But now I come to try this in Azure, all of my nice Json formatted data from Serilog is being ignored - and only the standard ILogger output is being shown :( Here's the config I'm using in Startup.ConfigureServices . services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(CreateLogger())); private static Logger CreateLogger() { var

Output JSON in Azure Function Logs

空扰寡人 提交于 2020-07-23 06:31:05
问题 We'd like to send structured log data from our Azure Functions to Event Hub. So I set up Serilog to log to the console and include all the info I wanted. But now I come to try this in Azure, all of my nice Json formatted data from Serilog is being ignored - and only the standard ILogger output is being shown :( Here's the config I'm using in Startup.ConfigureServices . services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(CreateLogger())); private static Logger CreateLogger() { var

Output JSON in Azure Function Logs

久未见 提交于 2020-07-23 06:30:51
问题 We'd like to send structured log data from our Azure Functions to Event Hub. So I set up Serilog to log to the console and include all the info I wanted. But now I come to try this in Azure, all of my nice Json formatted data from Serilog is being ignored - and only the standard ILogger output is being shown :( Here's the config I'm using in Startup.ConfigureServices . services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(CreateLogger())); private static Logger CreateLogger() { var

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

一世执手 提交于 2020-06-28 05:38:06
问题 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 configure that. For example, the following console app: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.2" />

Manage logging configuration with NLog in .NET Core 3

旧街凉风 提交于 2020-05-14 09:39:07
问题 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: 1. In the code where I need to create a logger in a dependency injection context // Other code... services.AddScoped<IApplyJcdsCommandsJob, ApplyJcdsCommandsJob>(provider => { var loggerFactory = LoggerFactory.Create(builder => { builder .ClearProviders() .AddFilter(

Unable to resolve ILogger from Microsoft.Extensions.Logging

随声附和 提交于 2020-01-12 12:51:36
问题 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 _logger; public MyClass(ILogger logger) { _logger = logger; } public void MyFunc() { _logger.Log(LogLevel.Error, "My Message"); } System.InvalidOperationException: 'Unable to resolve service for type 'Microsoft.Extensions.Logging.ILogger' I've tried the

Unable to resolve ILogger from Microsoft.Extensions.Logging

≡放荡痞女 提交于 2020-01-12 12:50:46
问题 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 _logger; public MyClass(ILogger logger) { _logger = logger; } public void MyFunc() { _logger.Log(LogLevel.Error, "My Message"); } System.InvalidOperationException: 'Unable to resolve service for type 'Microsoft.Extensions.Logging.ILogger' I've tried the

How to unit test with ILogger in ASP.NET Core

旧城冷巷雨未停 提交于 2019-12-29 11:43:13
问题 This is my controller: public class BlogController : Controller { private IDAO<Blog> _blogDAO; private readonly ILogger<BlogController> _logger; public BlogController(ILogger<BlogController> logger, IDAO<Blog> blogDAO) { this._blogDAO = blogDAO; this._logger = logger; } public IActionResult Index() { var blogs = this._blogDAO.GetMany(); this._logger.LogInformation("Index page say hello", new object[0]); return View(blogs); } } As you can see I have 2 dependencies, a IDAO and a ILogger And

How to unit test with ILogger in ASP.NET Core

若如初见. 提交于 2019-11-30 02:33:07
This is my controller: public class BlogController : Controller { private IDAO<Blog> _blogDAO; private readonly ILogger<BlogController> _logger; public BlogController(ILogger<BlogController> logger, IDAO<Blog> blogDAO) { this._blogDAO = blogDAO; this._logger = logger; } public IActionResult Index() { var blogs = this._blogDAO.GetMany(); this._logger.LogInformation("Index page say hello", new object[0]); return View(blogs); } } As you can see I have 2 dependencies, a IDAO and a ILogger And this is my test class, I use xUnit to test and Moq to create mock and stub, I can mock DAO easy, but with