我在老师课程的基础上制作了一个加入房间的功能,做完发现主sever中调用log4net的info方法无效了,不知道错在哪里,登陆时候调用数据库返回的info是能正确返回的。
我应该没动什么东西啊=。=
主服务端
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Photon.SocketServer;
using ExitGames.Logging;
using ExitGames.Logging.Log4Net;
using log4net.Config;
using System.IO;
using SurviveServer.Manager;
using Common;
using SurviveServer.Handler;
using SurviveServer.Threads;
namespace SurviveServer
{
//Server端主类都要继承
public class SurviveServer:ApplicationBase
{
public static readonly ILogger log = LogManager.GetCurrentClassLogger();
//当客户端请求链接时
public static SurviveServer Instance
{
get;
private set;
}
public Dictionary<OperationCode,BaseHandler> HandlerDict = new Dictionary<OperationCode,BaseHandler>();
public List<ClientPeer> peerList = new List<ClientPeer>();
public List<Room> RoomList = new List<Room>();
public Room LastRoom = new Room();
//线程
//public SyncPositionThread syncPositionThread = new SyncPositionThread();
protected override PeerBase CreatePeer(InitRequest initRequest)
{
log.Info("一个客户端链接过来了!");
ClientPeer peer = new ClientPeer(initRequest);
AddPeer(peer);
return peer;
}
public void AddPeer(ClientPeer peer) {
peerList.Add(peer);
if (LastRoom.Thread.isStart == true)
{
LastRoom = new Room();
RoomList.Add(LastRoom);
}
LastRoom.Thread.RoomPeer.Add(peer);
peer.CurrentRoom = LastRoom;
}
//初始化
protected override void Setup()
{
Instance = this;
//日志初始化
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);
XmlConfigurator.ConfigureAndWatch(configFileInfo);
}
RoomList.Add(LastRoom);
log.Info("Setup Completed!");
InitHandler();
}
public void InitHandler() {
LoginHandler loginHandler = new LoginHandler();
HandlerDict.Add(loginHandler.OpCode, loginHandler);
DefaultHandler defaultHandler = new DefaultHandler();
HandlerDict.Add(defaultHandler.OpCode, defaultHandler);
RegisterHandler registerHandler = new RegisterHandler();
HandlerDict.Add(registerHandler.OpCode, registerHandler);
SyncPositionHandler syncPositionHandler = new SyncPositionHandler();
HandlerDict.Add(syncPositionHandler.OpCode, syncPositionHandler);
SyncPlayerHandler syncPlayerHandler = new SyncPlayerHandler();
HandlerDict.Add(syncPlayerHandler.OpCode, syncPlayerHandler);
}
//关闭时
protected override void TearDown()
{
foreach (Room room in RoomList) {
room.Thread.Stop();
}
log.Info("服务器应用关闭了!");
}
}
}
LOG4NET.CONFIG
<?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}\\Survive.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>