Issue writing to single file in Web service in .NET

前端 未结 11 1813
天涯浪人
天涯浪人 2020-12-10 17:37

I have created a webservice in .net 2.0, C#. I need to log some information to a file whenever different methods are called by the web service clients.

The problem

11条回答
  •  隐瞒了意图╮
    2020-12-10 18:00

    The locking is probably failing because your webservice is being run by more than one worker process. You could protect the access with a named mutex, which is shared across processes, unlike the locks you get by using lock(someobject) {...}:

    Mutex lock = new Mutex("mymutex", false);
    
    lock.WaitOne();
    
    // access file
    
    lock.ReleaseMutex();
    

提交回复
热议问题