nlog

In NLog, is it possible to use layouts to define the log level?

旧街凉风 提交于 2019-12-11 04:55:05
问题 I would like to use Layouts in NLog to be able to change the minimum log level using an external variable : <nlog> <variable name="loglevel" value="Debug"/> <targets> <target ... /> </targets> <rules> <logger name="*" minlevel="${loglevel}" writeTo="LogFile" /> </rules> </nlog> After starting NLog, all log levels (eg : Tracing, Debug, Info, ...) are set to false which indicate NLog failed to parse minlevel attribute properly. The NLog layout feature seems to works with target attributes only.

How to log using vertical fields instead of horizontal columns?

让人想犯罪 __ 提交于 2019-12-11 04:46:13
问题 I'm using the NLog.EventLog target, and using the API I wish to log an event in vertical-field format. It might look something like this: Method: ServiceBase.Manager.StartService() Message: The service started successfully. Result: The service is listening for requests. Is this possible? 回答1: Sure, something like this: <target name="file" xsi:type="File" layout="Method: ${callsite} ${newline}Message: ${message} ${newline}Result: ${event-properties:result}" fileName="${basedir}/${level}.log" /

NLog per session

荒凉一梦 提交于 2019-12-11 03:39:19
问题 Is there any way to configure NLog to log information per application session? As of now it appends the messages in the log file each time application is executed (WinForm). What we'd like to have is to only store the info of the current session. Meaning that when application launches, all previous messages are cleared before any new message is logged. This way only the messages of current sessions will be available in the log file. Here is the current configuration <?xml version="1.0"?>

How to inject NLog using Autofac in ASP.NET Webforms

别说谁变了你拦得住时间么 提交于 2019-12-11 03:22:16
问题 I have an ASP.NET Webforms project that I've been recently converting to use Dependency Injection via Autofac. It has all been going well, that is until I tried to inject my NLog instances. I can't work out how to perform the equivalent of the static GetCurrentClassLogger() method calls with the property injected Logger object. Here is my sample code illustrating the problem: Global.asax.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using Autofac;

Target database not working with NLog 3.1 and Windsor Castle Logging Facility

你离开我真会死。 提交于 2019-12-11 02:04:42
问题 I'm able to log to a file using NLog, but the database is not created and if I create it manually, doesn't log anything. Is there something I might be missing? This is my NLog.config <?xml version="1.0" encoding="utf-8" ?> <target name="database" xsi:type="Database"> <connectionString> Server=.\SQLEXPRESS; Database=Logging; User Id=user; Password=password; </connectionString> <commandText> insert into LogEntries(Date,Level,Logger,Message,MachineName, UserName, Callsite, ThreadId, Exception,

NLog: How do I control the format of a message from a LogEventInfo object?

喜欢而已 提交于 2019-12-11 02:04:27
问题 I'm new to NLog, and I've been playing with LogEventInfo objects, since I think I'll need them in my application. I created a LogEventInfo object with a plain text string, and then I called Logger.Debug(myEventInfoObject), using a FileAppender set up to write ${message}. Where I expected to see my text string, I saw instead the logger name, the message level, the message, and the sequence ID. I found that that expanded string is what I get when I call myEventInfoObject.ToString(). How can I

NLog is not logging

吃可爱长大的小学妹 提交于 2019-12-10 21:45:49
问题 I am using the new NLog 2.0. I have set it up both manually and with the aid of NuGet on 2 different platforms: 1) on a Visual Web Developer express 2010 back at home. 2) On a Visual Studio 2010 in office. In both cases I just cant get it to log. I have read all of the options suggested here with no luck. I am using the very basic configuration from the first tutorial. <?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3

Why can't nlog read the current date

二次信任 提交于 2019-12-10 20:49:28
问题 I'm using Nlog to write some logging to a textfile. Partial nlog.config: <target name="file" xsi:type="File" fileName="${basedir}/MBWRunner_log.txt" layout="${date} (${level}): ${message} Exception: ${exception:format=Method, ToString}"/> Lines in the logfile look like this: 0001-01-01 00:00:00 (Trace): MBWRunner started As you can see the date and time are all 0. I have tested {longdate} and {date:format=yyyyMMddHHmmss} with the same result. The application is a console app, run from an

Where are logs located while running NUnit?

让人想犯罪 __ 提交于 2019-12-10 18:29:19
问题 I'm running NUnit tests from Resharper. I want to track execution process so my question is where can I find logs produced by my application? I use NLog, logger output path is relative, e.g. logs\mylog.txt . 回答1: I have a similar setup with my current project and for the unit tests, my NLog output goes to \UnitTests\bin\Debug\Logs. The logger is set up as follows in NLog.config (this produces a daily log file): <target name="FileLog" xsi:type="File" fileName="${basedir}/logs/${shortdate}_log

Is it possible to use the ${shortdate} in the internalLogFile?

百般思念 提交于 2019-12-10 17:52:03
问题 Is it possible to use the ${shortdate} in the internalLogFile ? <nlog internalLogFile="C:\Logs\${shortdate}_nlog.log" <targets> <target name="logfile" fileName="C:/logs/${shortdate}_dev.log" </target> I'm getting the expected dated logfile, but the internal log file is named ... ${shortdate}_nlog.log 回答1: Short answer: No. Longer answer: The internal logger file name is just a string. It's read in during initialization and the XmlLoggingConfiguration class ensures that the directory exists