photon 配置及日志输出

下载安装photon好 

下载证书添加到 deploy /bin_Win64 文件夹中

打开visio 新建类库 添加引用ExitGames.Logging.Log4Net.dll,ExitGamesLibs.dll,log4net.dll,Photon.SocketServer.dll,PhotonHostRuntimeInterfaces.dll

及Litjson.dll

新建类 继承自ApplicationBase 

//客户端连接
        protected override PeerBase CreatePeer(InitRequest initRequest)
        {
            return new MobaClient(initRequest);
        }
        //服务器初始化
        protected override void Setup()
        {
            InitLogging();
            LoginInfo("服务器初始化成功");
        }
        //服务器断开
        protected override void TearDown()
        {
            LoginInfo("服务器断开");
        }



        #region 日志功能
        private static readonly ILogger log = ExitGames.Logging.LogManager.GetCurrentClassLogger();

        private void InitLogging()
        {
            ExitGames.Logging.LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
            GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(this.ApplicationRootPath, "log");
            GlobalContext.Properties["LogFileName"] = "MOBA" + this.ApplicationName;
            XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(this.BinaryPath, "log4net.config")));
        }


        public static void LoginInfo(string text) {

            log.Info(text.ToString());
        }

        #endregion
新建类继承自ClientPeer

public MobaClient(InitRequest initRequest) : base(initRequest)
        {

        }
        //客户端断开连接
        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
        {

        }
        //客户端发起请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {

        }
之后更改deploy\bin_Win64 目录下的PhotonServer.config 这个配置文件

复制LoadBalancing标签内的代码进行配置

//更改成自己的项目服务器名称

    
    
    
      //UDP监听
      
      

    

    
    
      
      
      

      

      
      
      
    

    
    
      
      
      
      
      
    



    
    
    

    
    
    
      
      
      

      
      
      
    
  
将其发布在deploy目录下
之后运行启动后 就可以看见日志内容了

你可能感兴趣的:(Photon学习)