nlog

NLog config file to get configuration setting values from a web.config

≯℡__Kan透↙ 提交于 2019-12-18 04:44:11
问题 Is there a method to get a value from the <ApplicationSettings> section of a web.config within NLog layout variables? I already store SMTP details within my web.config and don't want to duplicate the settings just to use within my NLog.config. Ideally I'd like to do something like: ${aspnet-config:SmtpHostServer} which then fetches the value from the web.config 回答1: I couldn't see any obvious way to do this other than creating my own LayoutRenderer (see below). If you're putting into your own

Using NLog with F# Interactive in Visual Studio - Need documentation

ⅰ亾dé卋堺 提交于 2019-12-18 04:23:24
问题 I have a need to capture the input and output of F# functions when using F# Interactive. I am able to get NLog to work just fine when the program is run under Visual Studio using F5 or Ctrl-F5. Also the same methods that contain statements to output to the log work just fine and are called when invoked via F# Interactive; just nothing in the log file. I also tried the following with F# Interactive to setup references to NLog and still nothing in the log when run from F# Interactive. #I @"..

When should I use Tracing vs Logger.NET, Enterprise Library, log4net or Ukadc.Diagnostics?

只谈情不闲聊 提交于 2019-12-17 17:21:19
问题 How do I choose between standard tracing, Logger.NET, Enterprise Library, log4net or Ukadc.Diagnostics? Is there a situation where one is more appropriate than the other? ... what would that be? (ASP.NET, console app, Azure Cloud, SOHO, Enterprise...) What are the benefits or drawbacks? Did I miss any other major logging frameworks? 回答1: There are many similar questions here on SO: Logging best practices log4net versus TraceSource Silverlight Logging framework and/or best practices log4net vs

How Thread-Safe is NLog?

≡放荡痞女 提交于 2019-12-17 15:39:39
问题 Well, I have waited for days before deciding to post this issue, as I was not sure how to state this, resutling into a long detailed post. However, I think it is relevant to ask for the community's help at this point. Basically, I tried to use NLog to configure loggers for hundreds of threads. I thought this would be very straightforward, But I got this exception after few tens of seconds : " InvalidOperationException : Collection was modified; enumeration operation may not execute " Here is

Custom log4net property PatternLayoutConverter (with index)

风格不统一 提交于 2019-12-17 14:54:16
问题 Is it possible to create a log4net custom PatternLayoutConverter that allows an "index" value to be configured? I know about the "property" conversion string that allows you to write code like this: ThreadContext.Properties["ID"] = yourID; And specify like this: %property{ID} That the value should be included in the output. What if the values I want to log are in some other "dictionary"? I suppose that I could write some logic to copy those values from the dictionary to one of the log4net

How do I switch from Log4Net to NLog in Quartz.Net?

淺唱寂寞╮ 提交于 2019-12-17 13:05:41
问题 My company's standard logging tool is NLog. I'm trying to introduce Quartz.net and was asked if it could use NLog instead of Log4Net. I know I can recompile to use NLog, but I'd like to do it from the configuration files if at all possible. 回答1: Assuming that you're using Quartz.net 1.0.3. you have to add a reference to the following assemblies: Common.Logging Common.Logging.NLog NLog Then you have to add the following configuration in your application's config file: <configuration>

reconfiguring NLog programmatically

筅森魡賤 提交于 2019-12-17 10:46:07
问题 This is my first time using the NLog package for logging but so far its been great to work with. In my scenario I need to initialize my NLog LoggingConfiguration settings programmatically rather than thru the more typical config file scenario. I've tested this and got it all working the way I want it by default. But how would I go about modifying my settings programmatically at run-time? Probably the most common scenario here is one where the application's logging level is set to ERROR by

Dependency injection and named loggers

你。 提交于 2019-12-17 10:08:32
问题 I am interested in learning more about how people inject logging with dependency injection platforms. Although the links below and my examples refer to log4net and Unity, I am not necessarily going to use either of those. For dependency injection/IOC, I will probably use MEF as that is the standard that the rest of the project (large) is settling on. I am very new to dependency injection/ioc and am pretty new to C# and .NET (have written very little production code in C#/.NET after the past

How to retain callsite information when wrapping NLog

天大地大妈咪最大 提交于 2019-12-17 06:34:27
问题 I have a class that wraps NLog (called NLogger). My logs are saved to my database. The thing I'm having a problem with is how do I show where the logging occured. I have this <parameter name="@Logger" layout="${callsite}"/> but this just shows Core.Logging.Loggers.NLogLogger.Log which is my NlogWrapper not the class which calls my wrapper. This is my wrapper method public void Log(LogType messageType, Type context, string message, Exception exception) { NLog.Logger logger = NLog.LogManager

[.Net Core] 简单使用 Mvc 内置的 Ioc

这一生的挚爱 提交于 2019-12-16 14:43:36
[.Net Core] 在 Mvc 中简单使用日志组件 在 Mvc 中简单使用日志组件   基于 .Net Core 2.0,本文只是蜻蜓点水,并非深入浅出。 目录 使用内置的日志组件 简单过渡到第三方组件 - NLog 使用内置的日志   下面使用控制器 HomeController.cs 进行演示。   需要 using Microsoft.Extensions.Logging;   方案一: public class HomeController : Controller { private readonly ILogger _logger ; public HomeController(ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger(typeof(HomeController)); } }   方案二: public class HomeController : Controller { private readonly ILogger _logger ; public HomeController(ILogger<HomeController> logger) { _logger = logger; } }   方案三: public class HomeController :