Write to a log file in ASP.NET

前端 未结 3 2025
别跟我提以往
别跟我提以往 2020-12-31 17:47

I am writing event data to a log file in an asp.net httphandler by using the File.AppendAllText method. I am concerned with what will happen when multiple requests are rece

3条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-31 18:22

    no, you should have a static lock object guarding the log-file write, e.g.

    public static object LockingTarget = new object();
    
    public void LogToFile(string msg)
    {
        lock(LockingTarget)
        {
            //append to file here as fast as possible
        }
    }
    

提交回复
热议问题