我用两个控制台程序,各循环10000次,
引用同一个LOg4Net.DLL,并且对同一个文件同时写入Log。
每次循环写4行:
                    logger.Info(i + " log_test2");
                    logger.Info("程序已经启动");
                    logger.Info("程序没有错误");
                    logger.Info("程序开始调试");最后运行完,为什么数据行数不够呢
哪位知道?

解决方案 »

  1.   

    log4net配置错误,在控制台配置很麻烦的,我一般都是先在类库里边配置好,然后控制台再引用这个类库,贸下邮箱,可以发给你
      

  2.   

    1:思路不对。用两个程序操作一个文件,就好像用两个播放器放一个视频文件一样,会出现“文件被占用”错误。
    2:如果两个应用程序都是你自己的程序,你非要这么做,可以使用进程间锁Mutex,在对文件进行写入的时候锁定,估计就能满足你的要求了
      

  3.   

    回复icbc_ljt:
     [email protected]
      

  4.   


                bool requestInitialOwnership = true;
                bool mutexWasCreated;
                Mutex m = new Mutex(requestInitialOwnership,
                                                            "MyMutex ",
                                                            out   mutexWasCreated);
                if (!(requestInitialOwnership && mutexWasCreated))
                {
                    //Console.WriteLine("Waiting   for   the   named   mutex. ");
                    m.WaitOne();
                }            //Console.WriteLine("This   process   owns   the   named   mutex.   " +
                //            "Press   ENTER   to   release   the   mutex   and   exit. ");
                //Console.ReadLine();            log4net.ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                for (int i = 0; i < 10000; i++)
                {
                    logger.Info(i + " log_test2");
                    logger.Info("程序已经启动");
                    logger.Info("程序没有错误");
                    logger.Info("程序开始调试");
                }            m.ReleaseMutex();
    按照luminji的方法,我套了一层mutex,结果是对了。
    谢谢大家