Hi anyone know any better about this problem:
I sent this to support, and got the response below which errr kind of answered the "question"
My Support Request to MS:
Thanks for that, but there is a problem with this model:
If we have a web service which calls a codeunit which must log to a file.
We are finding that every so often the web service falls over, saying it can’t access the log file in question, presumably because the file is in use by another thread, which may have got the file lock and writing to it.
If we can’t use SingleInstance Codeunit to communicate across the threads then how do we prevent this file locking issue?
Example:
Webservice()
{
WriteToLogFile(‘log this’);
}
WriteToLogFile(str logmsg)
{
f.Openfile(“c:\file.log”);
f.Write(logmsg);
f.Close();
}
When writing to the log we are opening and closing the file as quickly as possible, however because of the concurrency and lack of communication between threads which apparently is not possible how do we prevent this problem?, I guess we could use a table as a semaphore to record access to the log file, but this is not ideal.
Support Response ->
Thanks for your clarification.
In a way, your example proves that web services really are multithreaded, which is the good news
.
You would need to find a way to lock the file, or some ways for multiple processes to write to the file at the same time. Each thread is completely separate so I am afraid you won’t be able to share the file.
Hope this helps. Waiting to hear fro you.
Best Regards,
Some Guy at MS. ( Not marks and spencers! )
Comments
RIS Plus, LLC
If you need to log to files - you have a log file for each Web Service Listener - and then put a timestamp in the log (if you need to merge the log's later).
Trying to have different processes waiting for each other seams only to hurt performance and not really help anybody.
Group Program Manager, Client
Microsoft Dynamics NAV
http://blogs.msdn.com/freddyk
The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
And therefore yes the table logging method seems to be the way, the issue is really is if you have a lot of legacy code which already logs to the file system then you have your work cut out.
if SETSTAMP(filename,newdate,newtime) then begin
end
to see if the file is locked. and wait till it is released. but in a sense you are making the file be your semaphore.
I would rather use events, send email, create separate files for each connection.
afterward at the end of the have a processing that will combine the files.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n