这个log类搞得我真纠结,首先继承的类都是封装的方法,看不懂。
log的使用
如何在服务器运行时输出log
1.根据Photon的Demo,首先在你的Program中添加引用
using ExitGames.Logging.Log4Net;
using ExitGames.Logging;
using log4net.Config;
using log4net;
using LogManager = ExitGames.Logging.LogManager;using LogManager = ExitGames.Logging.LogManager;是区分于log4net里的LogManager;
2.设置Log的配置
定义log变量:private static readonly ILogger log = LogManager.GetCurrentClassLogger();
该变量是LogManager的一个实例,不用管;然后配置log文件路径
protected override void Setup()
{
log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] =
Path.Combine(this.ApplicationRootPath, "log");
string path = Path.Combine(this.BinaryPath, "log4net.config");
var file = new FileInfo(path);
if (file.Exists)
{
LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
XmlConfigurator.ConfigureAndWatch(file);
}
}第一行:设置log文件在Photon根目录下的log文件夹内(../deploy/log);
行二行:设置配置文件路径(你的服务器DLL文件所在目录,没有则添加这个文件);
最后是读配置了,如果没有log4net.config就不会输出log的。
3.配置log4net.config文件;(没有可从MMODemo里复制出来)
找到第一段<appender></appender> 把file后的value改成其他名字(不要和log里其他文件重名);
4.写log,在需要的地方写log信息;如log.Info(“info”)....
启动Photon,即可在log文件下找到log文件,输出的log信息
OK.



















