Logging to open file

D

Drew

I have a small VB.NET application that captures left clicks, right clicks
and key presses and automatically logs them to a csv file every 1 minute.
The issue is that if I want to look at the log file, I get an error because
the app is trying to write to the log file and it is open.

How can I circumvent this issue?

Thanks,
Drew
 
C

Carlos J. Quintero [VB MVP]

When you look at the log file, are you opening it for read or for write?

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
D

Drew

I am opening it in Notepad, so I guess that I am opening it for writing...
How should I review this log while the program is running?

Do you want me to post all the code?

Thanks,
Drew
 
M

Mona

Hello Drew,

How are you doing?

Two ways to get out of this problem:
1) Copy the file and then open the copied file.
2) Create your own File reader in which you open a connection to the text
file in a ReadOnly mode.
And for this open a filestream instead. You can pass
System.IO.FileAccess.Read to the constructor.
Then you can create a new streamreader to read from the stream.

I hope this is helpful.

Thanks
Mona
[Grapecity]
 
C

Carlos J. Quintero [VB MVP]

Basically, you should not open the file to view it with an *editor*, which
by definition will open the file for write. If you don´t find a tool that
can open a file to view it with read-only access, you can build your own.
The .NET framework has functions to open streams for read-only access. See
the docs about the Stream and derived classes.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
D

Drew

Thank you for your reply. I will check out the functions that you mentioned
and see what I can do.

Thanks,
Drew
 
D

Drew

Thanks for your reply Mona, I will check out the suggested options and see
what I can find.

Thanks,
Drew

Mona said:
Hello Drew,

How are you doing?

Two ways to get out of this problem:
1) Copy the file and then open the copied file.
2) Create your own File reader in which you open a connection to the text
file in a ReadOnly mode.
And for this open a filestream instead. You can pass
System.IO.FileAccess.Read to the constructor.
Then you can create a new streamreader to read from the stream.

I hope this is helpful.

Thanks
Mona
[Grapecity]


Drew said:
I have a small VB.NET application that captures left clicks, right clicks
and key presses and automatically logs them to a csv file every 1 minute.
The issue is that if I want to look at the log file, I get an error because
the app is trying to write to the log file and it is open.

How can I circumvent this issue?

Thanks,
Drew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top