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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:54:20+00:00 2026-05-13T18:54:20+00:00

I have an VB.NET app that writes the status to a log file in

  • 0

I have an VB.NET app that writes the status to a log file in text format. Over time, the file is getting large and I wanted to know if there is an efficient way to truncate the beginning of the file.

To make things easier, I am looking to specify a file size (say 2-3 mb) and I am writing the log using a StreamWriter:

Using strm As New IO.StreamWriter(filelocation.log, True)
    strm.WriteLine("msg to write")
    strm.Close()
End Using

I thought about using the strm.BaseStream.Length to determine how much of the file to cut off, but by using the .SetLength it would cut from the end – not the desired result.

  • 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-13T18:54:21+00:00Added an answer on May 13, 2026 at 6:54 pm

    I would highly suggest looking at log4net to accomplish your logging. It’s extremely powerful and flexible and has a built in way of rolling your logs based on a size you can specify. It’s not the answer you’re looking for here, but it’s definitely worth looking into. Here’s a sample config for what we do for logging during debug:

    <log4net>
        <appender name="GeneralLog" type="log4net.Appender.RollingFileAppender">
            <file value="ClientTools.log"/>
            <appendToFile value="true"/>
            <maximumFileSize value="3000KB"/>
            <rollingStyle value="Size"/>
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%d{HH:mm:ss} [%t] %-5p %c - %m%n"/>
            </layout>
        </appender>
        <root>
            <level value="DEBUG"/>
            <appender-ref ref="GeneralLog"/>
        </root>
        <logger name="NHibernate" additivity="false">
            <level value="DEBUG"/>
            <appender-ref ref="GeneralLog"/>
        </logger>
    </log4net>
    

    This code in the app.config file will create a log file called ClientTools.log in the application folder, write it in a specific format including the date and time, and roll the log at 3MB.

    To use the logger, we do this in Init() of the web page:
    public ILog log;

    public void InitiateLogging()
    {
        log4net.Config.XmlConfigurator.Configure();
        log = LogManager.GetLogger("MyApplication");
    }
    

    And then when you want to log something, do this:

    log.Info("No resources available.");
    // or
    log.Fatal(exception.Message);
    // or
    log.Warn("Something bad may happen here.");
    

    You don’t have to worry about creating a stream object, closing the stream, disposing the stream, etc. And it’s very DRY.

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

Sidebar

Related Questions

Hello I have a page in an ASP.NET (website) project that writes a file
I have an asp.net 3.5 app that write a zip file to a directory(Ionic
We have a NET app that gets installed to the Program Files folder. The
I have this .NET web app that draws a table in Page_Load. Then after
I have a .NET client app that intermittently loses connection to a UNC share
I have an ASP.NET app that sits on our intranet, using the WindowsIdentity to
I have an asp.net app that uses System.IO.Path.GetTempFileName() for temporary files. In the production
I have a .Net (C#) app that uses Sql Express. Development is finished, and
I have a .Net 2.0 app that is used internally and we want to
I have an ASP.NET MVC app that opens a Request view in a new

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.