我在事件日志中看到一条消息:;全局缓存已发送到客户端[客户端id]

本文关键字:客户端 缓存 全局 id 日志 事件 消息 一条 | 更新日期: 2023-09-27 18:20:44

发送到客户端[client-id]的全局缓存。进程无法访问文件C:'LogFile.txt,因为其他进程正在使用该文件。

   public DataTable GetGlobalCache(out Guid serverGUID, Guid clientGUID, string clientIP)
    {
        **Logger.LogEvent(String.Format("GlobalCache sent to client {0} [IP:{1}]", clientGUID.ToString(), HttpContext.Current.Request.UserHostAddress.ToString()));**            
        if (GlobalEntities.CacheData == null) DBAccess.GetData();
        //Return our server guid
        serverGUID = GlobalEntities.ServerGUID;
        return GlobalEntities.CacheData;
    }
    public DataTable GetEventLog()
    {
        using (ECOMMEntities ecomm = new ECOMMEntities())
        {
            ObjectSet<EventLog> EventLogs = ecomm.EventLogs;             
            var query = from eventLog in EventLogs                             
                        select new
                        {
                            EventDate = eventLog.EventDate,
                            EventDescription = eventLog.EventDescription,
                            EventSource = eventLog.EventSource
                        };      
            var objquery = query as ObjectQuery;     
        }
        return new DataTable();
    }

我在事件日志中看到一条消息:;全局缓存已发送到客户端[客户端id]

实际上,消息清楚地说明了问题,正在使用"LogFile.txt"。您应该使用某种锁定机制来避免多个线程访问同一个文件。

/// somewhere on global
object loggerLock = new object(); 
public DataTable GetGlobalCache(out Guid serverGUID, Guid clientGUID, string clientIP)
{
    lock(loggerLock)
    {
        Logger.LogEvent(String.Format("GlobalCache sent to client {0} [IP:{1}]", clientGUID.ToString(), HttpContext.Current.Request.UserHostAddress.ToString()));**
    }
    if (GlobalEntities.CacheData == null) DBAccess.GetData();
    //Return our server guid
    serverGUID = GlobalEntities.ServerGUID;
    return GlobalEntities.CacheData;
}