jesintha roselin
jesintha roselin

Reputation: 171

I dont want nlog to create log file for every millisec

Im using the following config . This creates log file for every milli sec. I want only one log file per execution and it should be time stamped

<?xml version="1.0" encoding="utf-8"?>

<configuration>
 <configSections>
 <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>


<nlog 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"    fileName="C:\log\log-     ${date:format=dd/MM/yyyy HH\:mm\:ss}.txt"></target>   
</targets>

<rules>
  <logger name="*" minlevel="Info" writeTo="logfile" />
</rules>

Upvotes: 0

Views: 89

Answers (2)

Rolf Kristensen
Rolf Kristensen

Reputation: 19867

Have submitted a PR for the processinfo-layout-renderer, so it can output process-start-time in the wanted format. But it only supports local-time

fileName="C:\log\log-${processinfo:property=StartTime:format=yyyy-MM-dd_HHmmss}.log"

Upvotes: 1

Julian
Julian

Reputation: 36790

The only way to do this is to set the fileName programmatically.

E.g.

var logfileTarget = NLog.LogManager.Configuration.FindTargetByName<FileTarget>("logfile");
logfileTarget.FileName = "filename_with_date_and_ext"; //you can use layout renderers here.

See API docs

Upvotes: 1

Related Questions