nlog

NLog - Only log while debugging

谁都会走 提交于 2019-12-05 15:14:25
Take this simple NLog example configuration: <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <targets> <target name="logfile" xsi:type="File" fileName="file.txt" /> </targets> <rules> <logger name="*" minlevel="Debug" writeTo="logfile" /> </rules> </nlog> How can this be set up to only log while debugging, and not when run in production? EDIT: To make things a bit more challenging: My NLog configuration files are centralized, shared over all applications/services/sites. So I would like to avoid altering every single project and

How to write an NLog target using Signalr

徘徊边缘 提交于 2019-12-05 14:35:38
I'm trying to write a target for NLog to send messages out to connected clients using SignalR. Here's what I have now. What I'm wondering is should I be using resolving the ConnectionManager like this -or- somehow obtain a reference to the hub (SignalrTargetHub) and call a SendMessage method on it? Are there performance ramifications for either? [Target("Signalr")] public class SignalrTarget:TargetWithLayout { public SignalR.IConnectionManager ConnectionManager { get; set; } public SignalrTarget() { ConnectionManager = AspNetHost.DependencyResolver.Resolve<IConnectionManager>(); } protected

Nlog Async and Log Sequence

你。 提交于 2019-12-05 12:10:14
In my nlog configuration, I've set <targets async="true"> with the understanding that all logging now happens asynchronously to my application workflow. (and I have noticed a performance improvement, especially on the Email target). This has me thinking about log sequence though. I understand that with async, one has no guarantee of the order in which the OS will execute the async work. So if, in my web app, multiple requests come in to the same method, each logging their occurrence to NLog, does this really mean that the sequence in which the events appear in my log target will not

Is there a way in Log4Net or NLog (or some other logger) to output logs in an execution-stack-nested XML or JSON format?

谁都会走 提交于 2019-12-05 07:54:43
Is there a way in Log4Net or NLog (or some other logger) to output logs in an execution-stack-nested XML or JSON format, such that if function A() calls B(7) that calls C("something") , it'll output something like: <Method name="A"> <Method name="B" params="(int) 7"> <Method name="C" params="(string) 'something'"/> </Method> </Method> or even better: <Method name="A"> <Method name="B" params="(int) 7"> <Params> <int>7</int> </Params> <Method name="C"> <Params> <string>something</string> </Params> </Method> </Method> </Method> Why? so I'd be able to use (e.g.) XML Notepad or some JSON -viewer

How add NLog Class Library project in other projects

拈花ヽ惹草 提交于 2019-12-05 07:07:15
I have created a console project in C# and in that project I am using NLog for logging purpose. When I run the project, it successfully logging into to multiple targets like Console, File, EventLog and also to Sentinal. But when I make this project as a classLibrary and try to add the reference to another project, it's not logging to any of the targets. And of course there is no error in the project. Following is the code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using NLog; using NLog.Config; namespace NLogger { public

Configuring NLog to log exceptions in an XML output?

被刻印的时光 ゝ 提交于 2019-12-05 02:36:42
Currently, we have NLog spitting out CSV files just to prove we have NLog actually logging exceptions. <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" internalLogToConsole="true" internalLogToConsoleError="true"> <targets> <target name="file" xsi:type="File" fileName="${specialfolder:folder=ApplicationData}/log.csv"> <layout xsi:type="CSVLayout"> <column name="User_Machine_Name" layout="${machinename}" /> <column name="Time" layout="${date}" /> <column name="Level" layout="${level}" /> <column name="Message" layout="${message}" /

NLog - delete logs older than X days

牧云@^-^@ 提交于 2019-12-05 02:12:15
How I can delete files with logs older than X days. It's simple, but I have in one folder logs only from one day. My NLog.config looks like: <?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-instance" autoReload="true"> <extensions> <add assembly="NLog.Extended" /> </extensions> <variable name="LogHome" value="PATH"/> <variable name="DailyDir" value="${LogHome}${date:format=yyyy}/${date:format=MM}/${date:format=dd}/"/> <targets> <target name="asyncFile" xsi:type="AsyncWrapper"> <target name="fatalLog"

NLog not working in release mode

雨燕双飞 提交于 2019-12-04 23:40:13
I am using NLog to log the exceptions in my asp.net mvc (C#) application. NLog is not working in release mode. The same is working when running in debug mode. What may be the problem? Is there any fix for this? I was having the same problem as you: ASP.NET MVC 3 .NET 4 IIS 7 Release Mode I tried changing directories, and changing permissions to no avail. I even tried enabling the internal logging but even that didn't work! No failures, no exceptions, nothing! After doing some more investigating, I found the solution. For some reason, NLog wasn't loading the config file AT ALL. I realized this

Cannot load Exchange powershell snap-in: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception

笑着哭i 提交于 2019-12-04 17:36:58
问题 I have the following code that creates a PowerShell runspace with the Exchange 2010 snap in loaded. Dim runspaceConfig = RunspaceConfiguration.Create() Dim snapInException As PSSnapInException = Nothing runspaceConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", snapInException) Dim runspace = RunspaceFactory.CreateRunspace(runspaceConfig) runspace.Open() Since installing Visual Studio 2012 I started getting the following error when executing the line that adds the snap-in to

NLog Exception when parsing nlog.config - Target cannot be found: 'EventLog'

故事扮演 提交于 2019-12-04 17:00:26
I'm developing a C# .NET Core 2.2 Web-Api on Visual Studio 2017 . I implement NLog 4.6.1 like described on github . When I start my application using IIS NLog does not write into the Elasticsearch . A error occurs at the line at program.cs var logger = NLog.Web.NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger(); I find a error message at NLogError.log : 2019-06-12 09:00:49.1606 Error Penter code herearsing configuration from NLog.config failed. Exception: NLog.NLogConfigurationException: Exception when parsing NLog.config. ---> System.ArgumentException: Target cannot be found: