nlog

How Thread-Safe is NLog?

人盡茶涼 提交于 2019-11-27 19:22:21
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 the code. //Launches threads that initiate loggers class ThreadManager { //(...) for (int i = 0; i<500;

Why do loggers recommend using a logger per class?

本小妞迷上赌 提交于 2019-11-27 17:14:06
As per NLog's documentation: Most applications will use one logger per class, where the name of the logger is the same as the name of the class. This is the same way that log4net operates. Why is this a good practice? With log4net, using one logger per class makes it easy to capture the source of the log message (ie. the class writing to the log). If you don't have one logger per class, but instead have one logger for the entire app, you need to resort to more reflection tricks to know where the log messages are coming from. Compare the following: Log per class using System.Reflection; private

Why won't my windows service write to my log file?

本小妞迷上赌 提交于 2019-11-27 15:51:28
问题 I have a windows service and use nlog for logging. Everything works fine when I run from the visual studio ide. The log file updates with no issues. When I install the service, the service runs fine but the log file never updates. I am running under LOCAL SERVICE if that helps. Yes, I have created the logs directory under my application folder. <?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema

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

本小妞迷上赌 提交于 2019-11-27 15:16:10
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. LeftyX 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> <configSections> <sectionGroup name="common"> <section name="logging" type="Common.Logging

Injecting NLog with Autofac's RegisterGeneric

不羁的心 提交于 2019-11-27 14:11:33
问题 Note: Updated with suggested improvements, closer but still not quite there! Similar to this question - Passing in the type of the declaring class for NLog using Autofac - I am trying to inject NLog instances into my repository classes. Interface: public interface ILogger<T> where T: class { ... } Implementation: public class NLogger<T> : ILogger<T> where T: class { private readonly Logger _logger; public NLogger() { _logger = LogManager.GetLogger(typeof(T).FullName); } public void Debug

reconfiguring NLog programmatically

断了今生、忘了曾经 提交于 2019-11-27 12:37:41
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 default but a bug arises in a particular module that I want to switch the logging level to be much more

NLog rotate and cleanup logfiles

痴心易碎 提交于 2019-11-27 11:35:23
问题 Within my company we're working with NLog. We're experiencing issues with large amount of log files. What we want to do is archive files by day and keep a maximum of an x amount of files. Lets say 7. I've read several topics on the internet regarding this and they're mostly pointing me in the same direction of modifying my NLog.config file. However it doesn't seem to be willing to rotate the files as I expect it to do. Currently nothing is being archived in the desired folder. But all files

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

Dependency injection and named loggers

落花浮王杯 提交于 2019-11-27 10:14:37
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 10 years or so of VC6 and VB6). I have done a lot of investigation into the various logging solutions

using AppData location in NLog

ε祈祈猫儿з 提交于 2019-11-27 02:07:00
问题 My NLog targets is like this: <targets> <target xsi:type="Console" name="console" layout="${longdate}|${level}|${message}" /> <target xsi:type="File" name="ErrorLog" fileName="${basedir}/error.txt" layout="${longdate} Trace: ${stacktrace} ${message}" /> <target xsi:type="File" name="AccessLog" fileName="${basedir}/access.txt" layout="${shortdate} | ${message}" /> </targets> But this causes problems if the user isn't an admin on their machine, because they will not have write access to