基于PHOTON(光子)的服务器端开发III
Photon Server日志输出
1.日志生成
(1)在启动项目后,open logs生成日志,生成的日志位于bin_Win64下log文件夹内
2.日志配置
(1)引入插件log4net:依旧在lib文件夹下,找到log4net.dll,添加引用即可
(2)参照官网完成文件配置 log4net.config(或直接将photon自带配置文件复制过来进行配置,文件路径:Photon文件夹—>src-server文件夹—>Mmo文件夹—>Photon.MmoDemo.Server文件夹—>log4net.config—>复制到项目根目录)
(3)完成配置
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="false" update="Overwrite">
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="%property{Photon:ApplicationLogPath}\\PVP_demo.Server.log" />
<appendToFile value="true" />
<maximumFileSize value="5000KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="FATAL" />
</filter>
</appender>
<!-- logger -->
<root>
<level value="INFO" />
<!--<appender-ref ref="ConsoleAppender" />-->
<appender-ref ref="RollingFileAppender" />
</root>
<logger name="OperationData">
<level value="INFO" />
</logger>
</log4net>
(4)更改配置文件属性为:始终复制
3.日志初始化
(1)MyGameServer类:
using log4net.Config;
using ExitGames.Logging;
using ExitGames.Logging.Log4Net;
//引入命名空间
public static readonly ILogger log = LogManager.GetCurrentClassLogger();
//ILogger为log4net下的关键字
(2)Setup()方法里进行初始化:
protected override void Setup()
{
Instance = this;
//日志初始化
log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(this.ApplicationRootPath,"log");//获取根目录
FileInfo configFileInfo = new FileInfo( Path.Combine( this.BinaryPath,"log4net.config"));//获取部署文件路径
if (configFileInfo.Exists)
{
LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);//让Photon知道使用什么插件
XmlConfigurator.ConfigureAndWatch(configFileInfo);//让log4net读取配置文件
}
log.Info("Setup Completed!");//输出内容
}
つづく
基于PHOTON(光子)的服务器端开发III
https://baifabaiquan.cn/2020/08/10/基于Photon的服务器端开发3/