nlog

How to apply different layouts to the same target in NLog?

∥☆過路亽.° 提交于 2019-12-09 11:02:19
问题 NLog allows me to use SplitGroup to log my messages to several targets. I'd like to use this feature to log each message to a common, user-specific and date-specific logs at once: <variable name="commonLog" value="${logDir}\Common.log" /> <variable name="username" value="${identity:fSNormalize=true:authType=false:isAuthenticated=false}" /> <variable name="userLog" value="${logDir}\ByUser\${username}.log" /> <variable name="dateLog" value="${logDir}\ByDate\${shortdate}.log" /> <target name=

Registering NLog ILogger with Simple Injector

流过昼夜 提交于 2019-12-09 09:25:12
问题 Is there any way I can get the context so I can retrieve the loggerName and use LogManager.GetLogger(loggerName) instead of LogManager.GetCurrentClassLogger() ? I noticed container.RegisterConditional() has access to the context. Also, I want to avoid solutions like SimpleLogging.NLog for now. Finally, I am willing to accept this is not the right approach. BTW, AOP is an option that I've already explored (Is it a good practice to have logger as a singleton?). Note: I am aware that

Add current user to NLog output

这一生的挚爱 提交于 2019-12-09 08:31:14
问题 I want to add a string to each row on my NLog output. The logic stays the same, trying to get the current user and if succeed, add the current user to the output. I know how to implement it each time, but I want to set this template at one place and not repeat it on each writing. 回答1: The WindowsIdentityLayoutRenderer should probably give you what you want. You can choose to log either the Domain, the UserName, or both. You would configure it something like this (untested) to your NLog.config

Automatically log System.diagnostics.trace messages to an Nlog target

半城伤御伤魂 提交于 2019-12-09 02:53:19
问题 Say you have C# trace messages all over an application. Something like: Trace.TraceInformation("Service Started"); How do you automatically log this to an nLog target without having to add code like the following to all the classes that have trace messages? using NLog; private static Logger logger = LogManager.GetCurrentClassLogger(); Is there a way to do this without including traces produced by the .NET Framework itself, which this article demonstrates how to do? 回答1: This works for cases

NLog: can't write to event log

十年热恋 提交于 2019-12-08 23:27:07
问题 I can't write to the event log with NLog. I've been able to write to the console and to a file. I've turned on exceptions in NLog and am receiving no feedback from NLog. Here is my NLog.config: <?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" throwExceptions="true"> <targets> <target name="console" xsi:type="Console" layout="${message}" /> <target xsi:type="EventLog" name="eventlog" layout=

JsonSerializationException for type with private constructor

放肆的年华 提交于 2019-12-08 04:11:24
问题 I am persisting NLog logging statements to my RavenDb database. The LogEventInfo class, which represents a log statement, has a property, LogLevel , with a private constructor. Instances of LogLevel (Info, Warn, etc.) are created via static, readonly properties that call the private constructor. The problem is that I wish to read the messages out of the database and querying for them is throwing a Json.Net serialization error: Unable to find a constructor to use for type NLog.LogLevel. A

Configuring log4net to write to different files based on log level

房东的猫 提交于 2019-12-08 03:58:19
问题 I'm setting up log4net and want to write debug messages in "debug.log", info messages in "info.log" and so on. To this end, I use several appenders, such as: <appender name="DebugLogger" type="log4net.Appender.RollingFileAppender"> <file value="..\Logs\Debug.log" /> <threshold value="DEBUG" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="1MB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout

Is there a way to set the minlevel of a NLog logger via a variable?

岁酱吖の 提交于 2019-12-08 03:29:48
问题 Using NLog v4.4.12, I have this in my App.config <nlog> <include file="..\Common\Logs\Variables.xml" /> <rules> <logger name="*" minlevel="${logLevel}" writeTo="LogFile, Wcf"/> </rules> </nlog> And here is my Variables.xml file content <?xml version="1.0" encoding="utf-8"?> <nlog autoReload="true"> <variable name="logLevel" value="Fatal" /> </nlog> But I get an Exception when launching my app Unknown log level: ${logLevel} Am I doing something wrong or is it just impossible? The goal of this

NLog not writing to eventlog .NET Core 2.1

戏子无情 提交于 2019-12-08 03:13:15
问题 I've added NLog to my .NET core console app and it works with file and database targets. However when i try and get it to work with eventviewer it doesn't log anything. When i add the code for the eventviewer target the file and database part doesn't log anything. When I remove it, the logging starts working again. I have added a new event viewer source for the application using Powershell, so that wouldn't be the issue. The application doesn't crash or report an error, it runs fine but doesn

NLog: Force BufferingTargetWrapper to empty on AppDomain UnhandledException

╄→гoц情女王★ 提交于 2019-12-08 01:34:31
问题 I have NLog configured in my application to to use the BufferingTargetWrapper for sending emails with the MailTarget . The problem I'm running into is I can not find a way to force NLog to empty the BufferingTargetWrapper before the application exits from Unhandled Exceptions. I tried calling LogManager.Flush() and LogManager.DisableLogging() from the Current App Domain's UnhandledException Event but it does not seam to work. What would I need to do to make it send the emails? 回答1: you can