//初始化(当整个服务器启动起来的时候调用这个初始化) protected override void Setup() { //日志的初始化(定义配置文件log4net位置) //Path.Combine 表示连接目录和文件名,可以屏蔽平台的差异 // Photon: ApplicationLogPath 就是配置文件里面路径定义的属性 //this.ApplicationPath 表示可以获取photon的根目录,就是Photon-OnPremise-Server-SDK_v4-0-29-11263\deploy这个目录 //这一步是设置日志输出的文档文件的位置,这里我们把文档放在Photon-OnPremise-Server-SDK_v4-0-29-11263\deploy\bin_Win64\log里面 log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(Path.Combine(Path.Combine(this.ApplicationRootPath, "bin_win64")), "log"); //this.BinaryPath表示可以获取的部署目录就是目录Photon-OnPremise-Server-SDK_v4-0-29-11263\deploy\MyGameServer\bin FileInfo configFileInfo = new FileInfo(Path.Combine(this.BinaryPath, "log4net.config"));//告诉log4net日志的配置文件的位置 //如果这个配置文件存在 if (configFileInfo.Exists) { LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance); //设置photon我们使用哪个日志插件 XmlConfigurator.ConfigureAndWatch(configFileInfo); //让log4net这个插件读取配置文件 /*IUserManager userManager = new UserManager(); * log.Info(userManager.VerifyUser("Sure", "157")); * log.Info(userManager.VerifyUser("da", "25")); * log.Info(userManager.VerifyUser("kety", "123")); */ } for (int i = 0; i < 5; i++) { room[i] = new Room(i); } log.Info("Setup Completed!");//最后利用log对象就可以输出了 }
protected override void Setup() { var file = new FileInfo(Path.Combine(BinaryPath, "log4net.config")); if (file.Exists) { LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance); XmlConfigurator.ConfigureAndWatch(file); } Log.Info("Start server"); World.Instance.SpawnMobs(); }
public static void Initialize(GameApplication application) { log = LogManager.GetCurrentClassLogger(); log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(application.ApplicationRootPath, "log"); string configPath = Path.Combine(application.BinaryPath, "log4net.config"); FileInfo configFileInfo = new FileInfo(configPath); if (configFileInfo.Exists) { LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance); // 让Photon知道使用的是哪个日志插件(log4net) XmlConfigurator.ConfigureAndWatch(configFileInfo); // 让log4net读取配置文件 } Log("Debug系统初始化完成!"); }