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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:58:59+00:00 2026-05-22T15:58:59+00:00

Question: Is it posible to detect when a file, for wich a have an

  • 0

Question:

Is it posible to detect when a file, for wich a have an open FileStream, was renamed.

Case:

I am trying to monitor the logs for our application, I read from the logfiles since I do not want to interfere with the logging itself.

This works great until the file gets rolled. My application keeps reading from a renamed file without even noticing.

I tried using a FileSystemWatcher to detect the roll, but sometimes a get a lot of events, sometimes I don’t, so that’s not really a good solution (also the logfiles could reside on a network share wich could be an extra hold-back for using a FSW).

If I could find out which file(name) I have an open handle to, I could compare that to the _fileName but I don’t know how or if this can be done.

Are there any other options I could explore?

Code:

this is a simplified version of my filemonitoring class:

public class MonitorFile
{
    private String _fileName = String.Empty;
    private bool _stopMonitoring = false;

    public MonitorFile(string fileName)
    {
        _fileName = fileName;
    }

    // Simplified method
    public void StartMonitoring()
    {
        using (var reader = new StreamReader(
                    new FileStream(
                        _monitorFileName,
                        FileMode.Open,
                        FileAccess.Read,
                        FileShare.Delete | FileShare.ReadWrite)))
        {
            while (!_stopMonitoring)
            {
                Thread.Sleep(500);

                while ((line = reader.ReadLine()) != null)
                {
                    //...Do stuff with the lines
                }
            }
        }
    }
}
  • 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-22T15:59:00+00:00Added an answer on May 22, 2026 at 3:59 pm

    There is an MSDN example showing how you can obtain a file name from a file handle (which you have access to via the Handle property of the FileStream) using Win32 APIs, but I doubt this approach will work for files on a remote network share.

    You may well be out of luck in the general case.

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

Sidebar

Related Questions

Question So I've recently came up with some new possible projects that would have
This question is about App domains and Sessions. Is it possible to have IIS
A simple question. Is it possible to use bluetooth in iPhone to transfer file
I have a question on accessing already existing paired bluetooth connections... How can a
I have a two part question. The first I think I have an okay
I have a Subversion working copy with at least one missing file (the local
I have found following question: $0 (Program Name) in Java? Discover main class? but
Question: Is it possible to construct a web page that has a script to
It's quite possible a question like this has been asked before, but I can't
My question is simple; is it possible to over object-orient your code? How much

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.