Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我在事件日志中看到一条消息,说明“全局缓存已发送到客户端[客户端id]_C# - Fatal编程技术网

C# 我在事件日志中看到一条消息,说明“全局缓存已发送到客户端[客户端id]

C# 我在事件日志中看到一条消息,说明“全局缓存已发送到客户端[客户端id],c#,C#,已将全局缓存发送到客户端[客户端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.ToS

已将全局缓存发送到客户端[客户端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();
    }

实际上,这条消息清楚地说明了问题所在,“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;
}

感谢tolga的回复:。但问题是,我在eventviewer中看到了它,我不知道如何用锁功能复制问题和chck。你能告诉我如何复制它吗。提前谢谢你,不过我没有明白你的要求。什么是eventviewer?实际上它用于记录系统中的所有错误。任何未处理的异常都将记录在事件查看器中。转到运行->并给出eventvwr。它将显示系统中记录的事件。喜欢这个过程。我明白了,但我在你的代码片段中没有看到。你不能添加我提供的代码吗?我不知道如何复制这个问题。所以,如果我能找到复制的步骤,它会更有帮助