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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:06:09+00:00 2026-05-27T21:06:09+00:00

I am getting The process cannot access the file MyFile.log because it is being

  • 0

I am getting

The process cannot access the file “MyFile.log” because it is being used by another process.

while I am doing this

File.SetAttributes(filename,FileAttributes.Normal)

using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
    // Do stuff with log4net log
}

I have read other posts but they all suggest what I am already doing. Any other suggestions?

Thanks.

  • 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-27T21:06:09+00:00Added an answer on May 27, 2026 at 9:06 pm

    Try to configure log4net with a minimal lock:

    <appender name="FileAppender" type="log4net.Appender.FileAppender">
        ...
        <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
       ...
    </appender>
    

    have a look here for better explanation.

    Alternatively, try to open the log file with:

         using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite))
        {...
    }
    

    or check this project:Tailf
    In any case, remove the SetAttributes() part that could not work.
    Tailf Project Description
    Tailf is a C# implementation of the tail -f command available on unix/linux systems. Differently form other ports it does not lock the file in any way so it works even if other rename the file: this is expecially designed to works well with log4net rolling file appender.

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

Sidebar

Related Questions

I am getting a pretty common, The process cannot access the file because it
I am getting error as mentioned below: The process cannot access file E:\TempPDFs\Sample.pdf because
I am getting the The process cannot the file X because it is being
Hello I'm getting this error, while trying to save serial number to XML File.
here is the input i am getting from my flash file process.php?Q2=898&Aa=Grade1&Tim=0%3A0%3A12&Q1=908&Bb=lkj&Q4=jhj&Q3=08&Cc=North%20America&Q0=1 and in
when upload the same file for the multiple times i am getting this error......
Ol' newbie here again ... I'm getting this message cannot find symbol for all
Is there a way of getting the process id of my C++ application? I
How do I automate the process of getting an instance created and its function
I am in process of getting all hierarchical links from a given link and

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.