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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:01:44+00:00 2026-06-05T17:01:44+00:00

I’m using StreamWriter to write log file. And this is the writing log method,

  • 0

I’m using StreamWriter to write log file.

And this is the writing log method,

public void Write(string fileNamePrefix, string msg){
    GenerateFileName(fileNamePrefix);

    string logTime = "> "+DateTime.Now.ToShortDateString().ToString() + " " + DateTime.Now.ToLongTimeString().ToString()+"\r\n";

    using (StreamWriter sw = new StreamWriter(fileName, true))
    {
    sw.WriteLine(logTime + msg);
    sw.Flush();
    sw.Close();
    sw.Dispose();
    }
}

While using that method to write log, I got a error message that say ”
The process cannot access the file ‘C:\Users\mark\documents\visual studio 2010\Projects\eee\eee.WebUI\log\Order_20120613’ because it is being used by another process.“

Not all the time the error message occur, when I run many process at the same time and the processes are using that method to write log, then I get that error message.

anybody knows what I am doing wrong? how to avoid this error?

and is that right way for writing log? How do you write process log usually?

Thank you.

  • 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-05T17:01:48+00:00Added an answer on June 5, 2026 at 5:01 pm

    I/O failures are expected behavior for I/O related classes. So prepare to handle them.

    In you particular case it is most likely caused by file name collisions – make sure names for “log” files are unique between processes and threads in each process.

    Unrelated comments:

    • There is absolutely no need to call sw.Flush();sw.Close(); sw.Dispose(); if you are using using (since it is already correctly calls sw.Dispose() including exception cases). Even if you would not do that calling both Close and Dispose is of no value as both just call the same code.

    • Inventing (usually called “reinventing the wheel”) log writing and tracing libraries is traditional developers’ past time. Unless you consider it learning exercise or entertainment please use existing libraries like one that is already part of .Net framework (which lets you configure multiple trace listeners and so on) or other ones like Log4Net.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.