4

How to get the below output format using NLog error logging; A line separator between each exception log. like;
2017-06-19 16:53:20|SessionVal| Error message| Exception's Message | StackTrace _______________________________________________________________________________________ 2017-06-19 16:52:10|SessionVal|Error occured while executing the procedure. |Procedure xyz expects varchar(20) @ParameterName.|StackTrace....

Current NLog configuration;

<nlog autoReload="true" 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" 
   layout="${date:universalTime=false:format=yyyy-MM-dd HH\:mm\:ss}| 
   ${aspnet- session:Variable=SessionKey} ${message} | 
   ${exception:format=type,message,StackTrace}" 
   fileName="${basedir}/App_Data/Log/ 
   ${date:universalTime=false:format=yyyyMMdd}.log" />
   </targets>
  <rules>
    <logger name="*" minlevel="Info" writeTo="logfile" />
  </rules>
</nlog>

Update: @Amy, are you telling like this;
Update 2: Thank you @Amy it worked.
layout="-------------------------------------------------------------- ${newline}${date:universalTime=false:format=yyyy-MM-dd HH\:mm\:ss}| ${aspnet- session:Variable=SessionKey} ${message} | ${exception:format=type,message,StackTrace}" fileName="${basedir}/App_Data/Log/ ${date:universalTime=false:format=yyyyMMdd}.log"

c-sharp
  • 573
  • 1
  • 9
  • 25
  • Possible duplicate of [Nlog - Generating Header Section for a log file](https://stackoverflow.com/questions/4196663/nlog-generating-header-section-for-a-log-file) – Paul Karam Jun 20 '17 at 13:23
  • If I understood correctly then according to this thread https://github.com/NLog/NLog/issues/1713 header is logged only once per file. I need line separator between each exception log entry. – c-sharp Jun 20 '17 at 13:43
  • Why not just embed newline characters in the layout? –  Jun 20 '17 at 13:48
  • That's an option more of tedious, but was looking if there's any builtin feature to get it without changing in hundreds of different places. – c-sharp Jun 20 '17 at 13:58
  • 1
    No, this isn't built-in, and no, you wouldn't have to put it in hundreds of places. Your layout is right there in your NLog configuration. –  Jun 20 '17 at 14:01
  • @Amy Would you check the update please. – c-sharp Jun 20 '17 at 14:08
  • yes, with an embedded newline character –  Jun 20 '17 at 14:11
  • @c-sharp You can also use ${newline} https://github.com/NLog/NLog/wiki/Newline-Layout-Renderer – Rolf Kristensen Jun 20 '17 at 17:14
  • Please post your own answer as answer, and mark it. – Julian Jun 21 '17 at 16:17

1 Answers1

-1

According to the asker of the question this is a solution:

layout="-------------------------------------------------------------- 
    ${newline}${date:universalTime=false:format=yyyy-MM-dd HH\:mm\:ss}| 
    ${aspnet- session:Variable=SessionKey} ${message} | 
    ${exception:format=type,message,StackTrace}" 
    fileName="${basedir}/App_Data/Log/ 
    ${date:universalTime=false:format=yyyyMMdd}.log"
JorisJ1
  • 922
  • 2
  • 12
  • 22