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

  • Home
  • SEARCH
  • 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 9099649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:40:14+00:00 2026-06-17T00:40:14+00:00

I want to write a stand alone string (like a horizontal line or delimiter)

  • 0

I want to write a stand alone string (like a horizontal line or delimiter) to the log file.

If I use

string delimiter = "------------------------------------------------";
_logger.Info(delimiter);

then in the log file I get:

2013-01-08 15:58:54.4008 INFO ------------------------------------------------

I do not want the extra information at the beginning of the line.

Is there a way to write a separator like this with NLog? I checked the NLog wiki, but didn’t find anything.

  • 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-06-17T00:40:15+00:00Added an answer on June 17, 2026 at 12:40 am

    See my answer to a similar question here:

    Nlog – Generating Header Section for a log file

    To summarize, I propose defining another logging target. If you are logging to a file, define a second file target, pointing to the same file, but with a different layout. Define the layout so that it has the format that you want. You could define the layout to be hardcoded to the header value that you want (“—————” in your case), or your could define the layout to only log the message and then you could pass the layout to it.

    Here is the shortest thing that might work. Note, I cut and pasted from the answer linked above and modified slightly for your case. I did not test it.

    Define the layouts:

    <variable name="HeaderLayout" value="${message}"/>
    <variable name="FileLayout" value="${longdate} | ${logger} | ${level} | ${message}" />
    

    Define the targets using the layouts:

    <target name="fileHeader" xsi:type="File" fileName="xxx.log" layout="${HeaderLayout}" />
    <target name="file" xsi:type="File" fileName="xxx.log" layout="${InfoLayout}" />
    

    Define the rules/loggers:

    <rules>
      <logger name="headerlogger" minlevel="Trace" writeTo="fileHeader" final="true" />
      <logger name="*" minlevel="Trace" writeTo="file" />
    </rules>
    

    Use the loggers:

    public class MyClass
    {
      private static Logger logger = LogManager.GetCurrentClassLogger();
      private static Logger headerLogger = LogManager.GetLogger("headerlogger");
    
      public void DoSomething()
      {
        headerLogger.Info("---------------------");
        logger.Info("Inside DoSomething");
        headerLogger.Info("---------------------");
      }
    }
    

    Alternatively, you could define the layout such that it has the header definition in it:

    <variable name="HeaderLayout" value="-----------------------------"/>
    <variable name="FileLayout" value="${longdate} | ${logger} | ${level} | ${message}" />
    

    Then you would use it like this:

    Logger headerLogger = LogManager.GetLogger("headerlogger"); //Assuming same rules/loggers definition as above.
    
    headerLogger.Info("It doesn't matter what you put here because the layout has the header message hardcoded");
    

    You could write a helper function so that you don’t have to deal explicitly with the header logger:

    public void WriteHeader()
    {
      LogManager.GetLogger("headerlogger").Info("This string does not matter");
    }
    

    I think that this should give you some good insight into how you can accomplish what you are trying to do.

    Hope this helps!

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a file on my iPhone app. My file is in
I want to use an xml-file for storing my program data. The structure of
I want to be able to write XML to a String with the declaration
I want to write PHP script (standalone) for comment approval. Objective : I use
I'm developing a simple, stand-alone, command line Java application. The project is managed by
I have one stand alone client server application. I want to move it to
Is there a stand-alone GUI designer that can read and write the .form files
I am trying to understand how to develop stand-alone Javascript code. I want to
I want write a simple query which will fetch data from a table (which
I want write a little code analyzer which parses nested structures and translates into

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.