[#1011296] EventLog sometimes throw IO error while a text editor reading the same log file

View Trackers | Bugs | Download .csv | Monitor

2013-01-20 14:41
Submitted by:
chen huajun (chenhuajun)
Assigned to:
Nobody (None)
Npgsql Version:
EventLog sometimes throw IO error while a text editor reading the same log file

Detailed description
I run a program using npgsql with the EventLog outputing.
When the the program is runing ,i want to look the log infomation,
so i open the log file with a text editor.
sometimes(not always) it lead to npgsql throw a Exception :

file 'xxxxxx.log' is opened by other process,and can not be access.(*)
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access,
Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES
secAttrs,String msgPath, Boolean bFromProxy, Bool ean useLongPath)
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access , FileShare share, Int32
bufferSize,FileOptions options)
System.IO.StreamWriter.CreateFile(String path, Boolean append)
System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encod ing, Int32 bufferSize)
System.IO.StreamWriter..ctor(String path, Boolean append)
Npgsql.NpgsqlEventLog.LogMsg(NpgsqlConnection conn, String message, LogL evel msglevel)
Npgsql.NpgsqlEventLog.LogMethodEnter(NpgsqlConnection conn, LogLevel msg level, String ClassName,String MethodName)
Npgsql.ForwardsOnlyDataReader.GetProviderSpecificValue(Int32 ordinal)
Npgsql.ForwardsOnlyDataReader.GetValue(Int32 Index)

*)it's not the original message,the original message is not english in my environment,and i translated it english here.

I think the reason may be when Npgsql.NpgsqlEventLog.LogMsg() try to open the log file for writing just while the text editor is loading the same log file.


Date: 2013-01-21 14:09
Sender: chen huajun

It's true,my OS is Windows.
To avoid the problem what about opening log file only once and hold the StreamWriter object for next usage.
StreamWriter object will be closed at the end of the process or the log file name had been changed.
Date: 2013-01-21 12:26
Sender: Francisco Figueiredo jr.

Nice catch, Chen!

I'm not sure, but I think this problem only occurs when running on Windows, because other OS allow you to open the file while there are other programs reading it.

I don't know if there is much Npgsql can do about that, because if we do anything about this error, the user/developer won't know why Npgsql didn't log something.

Attached Files:


No Changes Have Been Made to This Item

Powered By FusionForge