Nlog: Log Header is printed only once per file

Created on 17 Oct 2016  路  7Comments  路  Source: NLog/NLog

Hi!

When using newest NLog version, the header is printed only once when creating the log file.

In earlier version of NLog the behavior was:

Application starting -> print header
Application running -> print log entries
Application terminating -> print footer

Now it seems, that the header is printed only when the log file is created, but not when the log file already exists.

Did I miss something?

Type: Question
NLog version: 4.3.10
Platform: .Net 3.5

Current 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"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off"
      internalLogFile="c:\temp\nlog-internal.log">

    <targets xsi:type="NLogTargets" async="false">

        <target xsi:type="File"
                name="fileTarget"
                fileName="${basedir}/logs/SvnBootstrapper.log"
                lineEnding="CRLF"
                archiveAboveSize="5048576"
                maxArchiveFiles="1"
                archiveNumbering="Rolling"
                header="${newline}
======================================================================================================================================================${newline}
Logging start = ${longdate}${newline}
Base dirctory = ${basedir}${newline}
Machine name  = ${machinename}${newline}
------------------------------------------------------------------------------------------------------------------------------------------------------${newline}
Date and Time            | Level | Module                                                | Message${newline}
------------------------------------------------------------------------------------------------------------------------------------------------------"
                layout=" ${longdate} | ${level:uppercase=true:padding=-5} | ${Logger:shortName=true:padding=20} | ${callsite:includeSourcePath=false:className=false:padding=30:fixedLength=true} | ${message} ${exception:format=message}"
                footer="${newline}
------------------------------------------------------------------------------------------------------------------------------------------------------${newline}
Logging end   = ${longdate}${newline}
======================================================================================================================================================" />
    </targets>

    <rules>

        <logger name="*" minlevel="Info" writeTo="fileTarget" />

    </rules>
</nlog>
file-target question

Most helpful comment

OK, please make a new issue so we could easier track this. Thanks!

it's a feature request

All 7 comments

Now it seems, that the header is printed only when the log file is created, but not when the log file already exists.

That's intended behavior.

In earlier version of NLog the behavior was:

Application starting -> print header
Application running -> print log entries
Application terminating -> print footer

That was a bug.

Maybe we should make it configurable?

I assume your question has been answered, if not, let us know!

Would it be possible, to make it configurable?

I'd also like the header to be printed for each session, not each log file.

If my app crashes the footer isn't printed and it's hard to tell two sessions apart.

What's a session in this case?

@304NotModified , session would be an instance run of my application. Starting and stopping it

OK, please make a new issue so we could easier track this. Thanks!

it's a feature request

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sszost picture sszost  路  3Comments

npandrei picture npandrei  路  3Comments

linmasaki picture linmasaki  路  3Comments

carkov1990 picture carkov1990  路  3Comments

imanushin picture imanushin  路  3Comments