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.