1.添加2个引用,下图两个带Log4Net.
2.添加log4net.config配置文件到根目录如图2,改属性为始终复制...文件可以到别的源码中找
3.添加下发加粗的代码,完成配置
namespace MyPhotonServer
{class MyPhotonServer: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.ApplicationPath, "bin_Win64"), "log");
FileInfo configFileInfo=new FileInfo(Path.Combine(this.BinaryPath, "log4net.config"));
if (configFileInfo.Exists)
{
LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
XmlConfigurator.ConfigureAndWatch(configFileInfo);
}
log.Info("Log 配置完成");
}protected override void TearDown()
{
log.Info("服务器应用关闭了!!!!!!");
}
}
}