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


I'm new to NLog, and I'm playing with the LogEventInfo object, because I think I want them 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 was expecting to see my text string, I saw logger's name, message level, message and sequence ID instead. I found that this is the extended string I get when I get my event infobee. I call toasting (). How can I control when $ {message} comes from a LogEventInfo object?

This is my config file:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Nlog xmlns = "http://www.nlog-project.org/schemas/NLog.xsd" xmlns: xsi = "http://www.w3.org/2001/XMLSchema -instance" throwExceptions = "true" & gt; ; & Lt; Goal & gt; & Lt; Target name = "file" xsi: type = "file" layout = "$ {longdate} $ {logger} $ {message}" filename = "$ {baseir} /nlog_sample_file.txt" /> & Lt; / Targets & gt; & Lt; Rules & gt; & Lt; Logger name = "*" minlevel = "debug" instrument = "file" /> & Lt; / Rules & gt; & Lt; / Nlog & gt;   

Here my code is generating the log:

  using the system; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using NLog; Namespace NLogSample {class program {static zero main (string [] args) {try {logger logger = logmanager. GetCurrentClassLogger (); LogEventInfo theEvent = New LogEventInfo (LogLevel.Debug, "", "This Message will not be used from LogInfoEvent."); TheEvent.Properties ["message"] = "This message will be used from the LogInfoEvent message property."; Logger.debug (theEvent); Logger.Debug ("Is Sequence ID appearing in this message?"); String formatted message = theEvent.FormattedMessage; String eventString = theEvent.ToString (); } Hold (Exception pre) {int a = 1; Finally, there is a sample of the message:  

2014-10-08 10: 14: 13.5525 NLogSample.Program log event: Logger = '' level = debug message = 'LogInfoEvent did not use this message Will go. ' Sequence ID = 2

I am working on a Win7 Pro machine in Visual Studio 2012.

Thanks a lot!

RobR

If you want to create LogEventInfo objects And want to fill them with your information, then you should logger Log method signing, logger.php / logger. Debug / ATC not the method signature.

The behavior you are seeing is probably due to the logger.debug method receiving an object (which is the LogEventInfo object) And calling it toString before entering it. / P>

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -