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 6837217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:27:03+00:00 2026-05-26T23:27:03+00:00

I am just wondering on a good way to write to log. I’ve created

  • 0

I am just wondering on a good way to write to log.

I’ve created a singleton class Logger which has 2 methods: Write(eventDate, messageType, message)
and Dispose().

In constructor I create StreamWriter (with AutoFlush set to true) which is used to append lines in a Write method. Logging is used extensively (but in one thread), about 10-15 records per second.

Now I reflect on the following two questions, comments on which I expect from you 🙂

First is autoflushing – does it open and close file all the time? Is File.AppendText similar?

Second, in Dispose I flush StreamWriter and then call Dispose on it. What if Dispose isn’t called? How can I make sure it will be disposed of? Because if I remove AutoFlush and will flush the stream time to time (may be by maintaining inner counter) and when n records are written to buffer, I’d flush it, but what if less than n records are written and program terminates?

  • 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-26T23:27:04+00:00Added an answer on May 26, 2026 at 11:27 pm

    Is there any reason you can’t use an open source logging framework such as NLog?

    It’s pretty easy to set up to write to a file

    Here is a really easy way to write your first logs to a file:

    1. Right-click references
    2. Click on Manage NuGet References
    3. Make sure the “Online” tab on the left is selected, and search for “NLog”
    4. Install “NLog Schema for Intellisense(TM)” (this will automatically install an xml NLog.config and the xsd file for xml intellisense support and pull in the references needed for NLog) NLog Schema for Intellisense(TM)
    5. Open the automatically created NLog.config file and uncomment the sample target and rule, they should look like so:

      <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
              layout="${longdate} ${uppercase:${level}} ${message}" />
      

      <logger name="*" minlevel="Trace" writeTo="f" />
      

    6. Now you are all set up to log stuff, with the sample configuration whenever you log something it will append it to a {shortdate}.log file under the /logs directory where the executable is run, so if you did something like:
      var logger = NLog.LogManager.GetLogger("SampleLogger");
      logger.Trace("Logged Trace");
      logger.Debug("Logged Debug");
      logger.Info("Logged Info");
      logger.Warn("Logged Warn");
      logger.Error("Logged Error");
      logger.Fatal("Logged Fatal");
      

    you'll get this log file

    NLog File

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

Sidebar

Related Questions

Wondering if anyone has written or come across a good way to log to
Just wondering if anyone has some good resources for learning how to create new
Just wondering whether there is a good way to upsert items in a CoreData
I was just wondering what a good way would be to get the user's
I was just wondering if the following way is a good one for building
gcc 4.6.2 c89 I am just wondering if this is a good way to
I'm wondering what a good way is to log a user in immediately after
Just wondering if the following is considered to be good programming practice or not?
I am just wondering if anyone know of some good tutorials on the Internet
I was just wondering if any one knows of a good script to emulate

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.