1.添加引用log4net.dll和ExitGames.Logging.Log4Net.dll

2.在项目中添加一个log4net的config文件,并且在PhotonServer的src下面的MMo下面的Server下面的log4net.config的内容复制给我们项目中刚才添加的。


上图config中的内容是需要更改的
3.并且将复制到输入目录设置为始终复制

4.更改config配置。将value后面那块圈出来的位置,改成自己的deploy中创建的文件夹的名字,我自己的是RRGameServer

把config的配置复制给大家吧
5.在MyGameServer中配置
MyGameServer.cs:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExitGames.Logging;
using ExitGames.Logging.Log4Net;
using log4net.Config;
using Photon.SocketServer;namespace RRGameServer
{//所有的Server,都要继承ApplicationBase,然后实现ApplicationBase的三个方法public class MyGameServer : ApplicationBase{private static readonly ILogger log = LogManager.GetCurrentClassLogger();//当有一个客户端连接上以后,就会执行此方法protected override PeerBase CreatePeer(InitRequest initRequest){log.Info("一个客户端连接");return new ClientPeer(initRequest);}//服务器初始化函数protected override void Setup(){log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(Path.Combine(this.ApplicationRootPath, "bin_Win64"), "log");FileInfo configFileInfo = new FileInfo(Path.Combine(this.BinaryPath, "log4net.config"));if (configFileInfo.Exists){LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);//photon知道日志输出XmlConfigurator.ConfigureAndWatch(configFileInfo);//读取配置}log.Info("服务器启动啦");}//服务器关闭函数protected override void TearDown(){log.Info("服务器关闭啦");}}
}
6.重新生成dll文件,并且全部复制
7.启动我们的photonServer,在关闭,然后查看日志

成功配置(●'◡'●)
对了最后附上xmind图,具体流程结合前面几篇一起看哦
