ms-extensions-logging

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

泄露秘密 提交于 2019-11-30 12:11:55
问题 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

Use NLog in ASP.NET Core application

戏子无情 提交于 2019-11-28 18:16:40
I found a CodeProject with an example of how to get this to work, but it doesn't work. The main problem seems to be that the "Microsoft.Framework.Logging.NLog": "1.0.0-*" package doesn't seem to exist in Nuget. I've looked at this StackOverflow question and looked at the GitHub example it references, but it seems to contain the same issue. I've tried to get it working on my own and the best I've come up with is the following: public class NLogLogger : ILogger { public NLogLogger() { new WebLoggerConfigurer().ConfigureDefault(); } public void Log(LogLevel logLevel, int eventId, object state,

Implementation and usage of logger wrapper for Microsoft.Extensions.Logging

六月ゝ 毕业季﹏ 提交于 2019-11-28 10:34:00
This question is related to Steven ’s answer - here . He proposed a very good logger wrapper. I will paste his code below: public interface ILogger { void Log(LogEntry entry); } public static class LoggerExtensions { public static void Log(this ILogger logger, string message) { logger.Log(new LogEntry(LoggingEventType.Information, message, null)); } public static void Log(this ILogger logger, Exception exception) { logger.Log(new LogEntry(LoggingEventType.Error, exception.Message, exception)); } // More methods here. } So, my question is what is the proper way to create implementation that

Use NLog in ASP.NET Core application

∥☆過路亽.° 提交于 2019-11-27 11:11:43
问题 I found a CodeProject with an example of how to get this to work, but it doesn't work. The main problem seems to be that the "Microsoft.Framework.Logging.NLog": "1.0.0-*" package doesn't seem to exist in Nuget. I've looked at this StackOverflow question and looked at the GitHub example it references, but it seems to contain the same issue. I've tried to get it working on my own and the best I've come up with is the following: public class NLogLogger : ILogger { public NLogLogger() { new

Implementation and usage of logger wrapper for Microsoft.Extensions.Logging

梦想的初衷 提交于 2019-11-27 03:39:54
问题 This question is related to Steven’s answer - here. He proposed a very good logger wrapper. I will paste his code below: public interface ILogger { void Log(LogEntry entry); } public static class LoggerExtensions { public static void Log(this ILogger logger, string message) { logger.Log(new LogEntry(LoggingEventType.Information, message, null)); } public static void Log(this ILogger logger, Exception exception) { logger.Log(new LogEntry(LoggingEventType.Error, exception.Message, exception));