ms-extensions-logging

NLog EventProperties in .NET Core

Deadly 提交于 2020-04-16 04:32:08
问题 I'm using ILogger<MyController> to write logs using DI (see step 6) I'm also using NLog EventProperties I want to add traceId to all my logs in my controller automatically. This is working: logger.Info("Some log. TraceId:{traceId}", 123); However, then I need to change all my log commands (a lot of them!), which is a pain. If I do the following, it's not tread safe: using NLog; public class MyController : Controller { private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

NLog EventProperties in .NET Core

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-16 04:31:00
问题 I'm using ILogger<MyController> to write logs using DI (see step 6) I'm also using NLog EventProperties I want to add traceId to all my logs in my controller automatically. This is working: logger.Info("Some log. TraceId:{traceId}", 123); However, then I need to change all my log commands (a lot of them!), which is a pain. If I do the following, it's not tread safe: using NLog; public class MyController : Controller { private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

How to include logging scope into the log file using NLog

雨燕双飞 提交于 2020-04-07 04:27:34
问题 I'm using NLog.Extensions.Logging . When registering a logger factory using the method AddNLog() , it is possible to enable logging scope using NLogProviderOptions.IncludeScopes . But how to make NLog write logging scope to a file? I haven't found anything similar in the list of available layouts 回答1: An example: Log like this: // logger is here of type Microsoft.Extensions.Logging.ILogger using (logger.BeginScope(new[] { new KeyValuePair<string, object>("userid", request.UserId) })) { logger

How to include logging scope into the log file using NLog

别等时光非礼了梦想. 提交于 2020-04-07 04:22:57
问题 I'm using NLog.Extensions.Logging . When registering a logger factory using the method AddNLog() , it is possible to enable logging scope using NLogProviderOptions.IncludeScopes . But how to make NLog write logging scope to a file? I haven't found anything similar in the list of available layouts 回答1: An example: Log like this: // logger is here of type Microsoft.Extensions.Logging.ILogger using (logger.BeginScope(new[] { new KeyValuePair<string, object>("userid", request.UserId) })) { logger

How to include logging scope into the log file using NLog

别说谁变了你拦得住时间么 提交于 2020-04-07 04:22:28
问题 I'm using NLog.Extensions.Logging . When registering a logger factory using the method AddNLog() , it is possible to enable logging scope using NLogProviderOptions.IncludeScopes . But how to make NLog write logging scope to a file? I haven't found anything similar in the list of available layouts 回答1: An example: Log like this: // logger is here of type Microsoft.Extensions.Logging.ILogger using (logger.BeginScope(new[] { new KeyValuePair<string, object>("userid", request.UserId) })) { logger

asp.net mvc core The call is ambiguous between the following methods or properties:

狂风中的少年 提交于 2019-12-20 01:17:11
问题 I am working on an application, and I got an error in Startup.cs partial classes, and I cant find why this error shows up: The call is ambiguous between the following methods or properties: Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action) Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection

netcore not logging to console

梦想与她 提交于 2019-12-03 23:55:18
问题 I have a simple test project to experiment with logging with NetCore 2.0 using the Microsoft Logging Extensions package. The problem I'm having is that when I run my app the very first time, it logs informational messages as expected. The weird behavior I'm having though is that subsequent runs won't produce any messages at all. My project targets the Net Core 2.0 framework, and has the following NuGet packages installed: Microsoft.Extensions.Logging Microsoft.Extensions.Logging.Abstractions

Simple Injector: Register ILogger<T> by using ILoggerFactory.CreateLogger<T>()

ぐ巨炮叔叔 提交于 2019-12-02 19:33:12
I'm working with a project which utilizes Simple Injector as dependency injector. On the other hand, this project uses Microsoft.Extensions.Logging in order to log the events that occurs in certain classes. My technical issue is pretty simple to explain. I want to register in my DI the ILogger independently of the class T which is being invoked, but I DO NEED to do it from my ILoggerFactory.CreateLogger<T>() method because this gets the logger configuration using Microsoft.Extensions.Configuration . I need to use something like this in order to instance my logger: private Microsoft.Extensions

Asp.Net 5 (core) RC1: How to log to file (rolling file logging) [DNX Core 5 compatible solution]?

雨燕双飞 提交于 2019-12-01 17:04:16
How can I log to file in Asp.Net 5 RC1? I couldn't find any solution with Microsoft.Extensions.Logging. Is there any solution which is compatible with .Net Core 5 (DNX Core 5.0)? I also was trying to use Serilog but Serilog doesn't support core 5 yet. To use Serilog in your ASP.NET 5 RC1 project, add the following dependencies in your project.json file: "Serilog.Extensions.Logging": "1.0.0-rc1-final-10092", "Serilog.Sinks.RollingFile": "2.0.0-beta-465" Create the logger in the Startup constructor: public Startup(IApplicationEnvironment appEnv) { Log.Logger = new LoggerConfiguration()

Asp.Net 5 (core) RC1: How to log to file (rolling file logging) [DNX Core 5 compatible solution]?

十年热恋 提交于 2019-12-01 16:15:31
问题 How can I log to file in Asp.Net 5 RC1? I couldn't find any solution with Microsoft.Extensions.Logging. Is there any solution which is compatible with .Net Core 5 (DNX Core 5.0)? I also was trying to use Serilog but Serilog doesn't support core 5 yet. 回答1: To use Serilog in your ASP.NET 5 RC1 project, add the following dependencies in your project.json file: "Serilog.Extensions.Logging": "1.0.0-rc1-final-10092", "Serilog.Sinks.RollingFile": "2.0.0-beta-465" Create the logger in the Startup