Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6781339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:36:45+00:00 2026-05-26T16:36:45+00:00

Within my company we’re working with NLog. We’re experiencing issues with large amount of

  • 0

Within my company we’re working with NLog. We’re experiencing issues with large amount of log files. What we want to do is archive files by day and keep a maximum of an x amount of files. Lets say 7. I’ve read several topics on the internet regarding this and they’re mostly pointing me in the same direction of modifying my NLog.config file. However it doesn’t seem to be willing to rotate the files as I expect it to do. Currently nothing is being archived in the desired folder. But all files are saved in the ‘logs’-directory in the following format;

Log.info.2011-11-07.txt

Within my application i’ve got an directory ‘logs’. Inside that folder all logfiles are saved. I’ve also got an folder called ‘archives’ in which I want to archive all older files. After the maximum number of log files is reached inside that directory they automatically should be cleaned. Is this possible? My current NLog.config file looks like below;

<?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"
      autoReload="true"
      throwExceptions="true"
      internalLogFile="C:\nlog-internal.txt"
      internalLogLevel="Error">

  <extensions>
    <add assembly="NLog.Extended" />
  </extensions>

  <targets>
    <!-- will move file to archive once it reaches 1MB. Files are archived by day, with a maximum of three files. ConcurrentWrites is set to false, 
            change to true if multiple processes will be writing to the logfile-->
    <target name="file" xsi:type="File" fileName="${basedir}/logs/Log.info.${shortdate}.txt" 
            layout="${longdate} ${callsite} ${level}: ${message} ${exception:format=Message,StackTrace} ${stacktrace}"
            archiveFileName="${basedir}/logs/archives/log.info.${shortdate}.txt"
            archiveAboveSize="1048576"
            archiveEvery="Day"
            archiveNumbering = "Rolling"
            maxArchiveFiles="7"
            concurrentWrites="false"
            />
    <target name="file-default" xsi:type="File" fileName="${basedir}/log_default.txt"/>
    <target name="file-debug" xsi:type="File" fileName="${basedir}/log_debug.txt"/>
    <target name="file-testclass" xsi:type="File" fileName="${basedir}/log_testclass.txt"/>
    <target name="mail" xsi:type="Mail" 
            subject="${level} - ${aspnet-request:serverVariabele=PATH_INFO} | ${callsite:includeSourcePath=true}" 
            to="someone@mail.com" 
            smtpServer="mail.server.com" 
            from="no-reply@errormail.com"/>
    <target xsi:type="Database" 
            name="TestDatabaseLogging" 
            connectionString="Data Source=123.123.123.123;Initial Catalog=NLog_Test;User ID=su_Nlog;Password=test123" 
            dbDatabase="NLog_Test">
      <commandText>
        insert into INNO_LOG ([createDate], [Origin], [LogLevel], [Message], [Exception], [StackTrace]) values (@createDate, @origin, @logLevel, @message, @exception, @stackTrace)
      </commandText>
      <parameter name="@createDate" layout="${date}"/>
      <parameter name="@origin" layout="${callsite}"/>
      <parameter name="@logLevel" layout="${level}"/>
      <parameter name="@message" layout="${message}"/>
      <parameter name="@exception" layout="${exception:format=Message,StackTrace}"/>
      <parameter name="@stackTrace" layout="${stacktrace}"/>
    </target>

  </targets>

  <rules>
    <logger name="*" minlevel="Fatal" writeTo="mail" />
    <logger name="*" minlevel="Error" writeTo="TestDatabaseLogging" />
    <logger name="*" minlevel="Debug" writeTo="file-debug" />
    <logger name="*" minlevel="Info" writeTo="file" />
    <!--Log to specific files for specific classes.-->
    <logger name="_Default" minlevel="Trace" writeTo="file-default" />
    <logger name="TestClass" minlevel="Trace" writeTo="file-testclass" />
  </rules>
</nlog>

EDIT:
The final (snipped) solution after ckellers answer.

<target name="file"
            xsi:type="File"
            fileName="${basedir}/logs/Log.${level}.current.txt"
            layout="${longdate} ${callsite} ${level}: ${message} ${exception:format=Message,StackTrace} ${stacktrace}"
            archiveFileName="${basedir}/logs/archives/log.error.${shortdate}.{#}.txt"
            archiveAboveSize="5242880"
            archiveEvery="Day"
            archiveNumbering = "Rolling"
            maxArchiveFiles="3" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:36:46+00:00Added an answer on May 26, 2026 at 4:36 pm

    It looks like the problem is the shortdate in your filename definition. See my answer at this question: Delete log files after x days

    You have to define the filename without the date part

    fileName="${basedir}/logs/Log.info.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working at a small company within a rather large company, where I don't
I'm writing a ASP.NET application used within our company. Now I want to send
I'm starting to do a small amount of development within my company. I'm intending
I have a large .NET based system running within the company intranet, which allows
I'm currently working on a page within one of my company's internet sites that
I'm working on a little experimental utility to use within our company that indexes
Background to this problem: Within out company we are working on an add-on to
I want to develop a website that will allow analysts within the company to
Within our company we use a proprietary template engine, which stores its templates in
I'm porting over some code from one project to another within my company and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.