我是Photon和Unit3d的新手,所以我刚刚安装了一个光子服务器并用 log4net.config 制作了一个小例子脚本,但我没有在我的光子服务器中看到任何调试消息,只有信息,我修改了log4net.config。
我的xml代码:
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="true">
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %-30.30c{2} %m% [%t] [%x]%n" />
</layout>
</appender>
<!-- "normal" log file appender -->
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="%property{Photon:ApplicationLogPath}\\sOnline.log" />
<!--param name="File" value="log\Lite.log" /-->
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="1" />
<param name="MaximumFileSize" value="250MB" />
<param name="RollingStyle" value="Size" />
<param name="LockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<!-- performance counter log file appender -->
<appender name="CounterAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="%property{Photon:ApplicationLogPath}\\sOnlineCounter.log" />
<!--param name="File" value="log\LiteCounter.log" /-->
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="1" />
<param name="MaximumFileSize" value="1MB" />
<param name="RollingStyle" value="Size" />
<param name="StaticLogFileName" value="true" />
<param name="LockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %m%n" />
</layout>
</appender>
<!-- logger -->
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="ConsoleAppender" />
</root>
<!-- operation data logger -->
<!-- set level to DEBUG to enable operation data logging-->
<logger name="OperationData" additivity="false">
<level value="INFO" />
<appender-ref ref="LogFileAppender" />
</logger>
<!-- performance counter logger -->
<!-- set level to DEBUG to enable performance counter logging-->
<logger name="PerformanceCounter" additivity="false">
<level value="INFO" />
<appender-ref ref="CounterAppender" />
</logger>
<logger name="ExitGames.Diagnostics.Monitoring.CounterSampleSender" additivity="false">
<level value="INFO" />
<appender-ref ref="CounterAppender" />
</logger>
</log4net>
和这个C#脚本:
using ExitGames.Logging;
using ExitGames.Logging.Log4Net;
using log4net.Config;
using Photon.SocketServer;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sOnline
{
public class PhotonServer : ApplicationBase
{
#region Overload of ApplicationBase
protected override PeerBase CreatePeer(InitRequest initRequest)
{
return new UnityClient(initRequest.Protocol, initRequest.PhotonPeer);
}
protected override void Setup()
{
var file = new FileInfo(Path.Combine(BinaryPath, "log4net.config"));
if (file.Exists)
{
LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
XmlConfigurator.ConfigureAndWatch(file);
}
}
protected override void TearDown()
{
}
#endregion
}
}
这是日志消息
2014-06-02 15:55:36,299 [17] INFO Photon.SocketServer.ApplicationBase [(null)] - Application start: AppId=sOnline; AppPath=F:\Photon\deploy\sOnline, Type=sOnline.PhotonServer
2014-06-02 15:55:36,379 [17] INFO Photon.SocketServer.ApplicationBase [(null)] - Application is stopping: AppId=sOnline
2014-06-02 15:55:36,382 [17] INFO Photon.SocketServer.ApplicationBase [(null)] - Application stop: AppId=sOnline
请帮助我:)
答案 0 :(得分:0)
<file type="log4net.Util.PatternString" value="%property{Photon:ApplicationLogPath}\\sOnline.log" />
我没有看到为ConsoleAppender设置的上述属性。
<root>
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
</root>
在xml中添加它并尝试它是否有效。
答案 1 :(得分:0)
如果您在log4net.config中使用 {Photon:ApplicationLogPath} 属性,则需要在 Setup 方法中指定它(请参阅下面的代码示例)。
要澄清 - 日志文件已创建,但您只能看到&#34; INFO&#34;消息,没有&#34; DEBUG&#34;消息 - 对吗? 你真的做了什么登录&#34; DEBUG&#34;水平?尝试向您的安装方法添加DEBUG日志消息,如下所示:
using ExitGames.Logging;
using ExitGames.Logging.Log4Net;
using log4net.Config;
using Photon.SocketServer;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sOnline
{
public class PhotonServer : ApplicationBase
{
private static readonly ILogger log = LogManager.GetCurrentClassLogger();
#region Overload of ApplicationBase
protected override PeerBase CreatePeer(InitRequest initRequest)
{
return new UnityClient(initRequest.Protocol, initRequest.PhotonPeer);
}
protected override void Setup()
{
var file = new FileInfo(Path.Combine(BinaryPath, "log4net.config"));
if (file.Exists)
{
LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(this.ApplicationRootPath, "log");
XmlConfigurator.ConfigureAndWatch(file);
}
if (log.IsDebugEnabled)
{
log.Debug("Setup done.");
}
}
protected override void TearDown()
{
}
#endregion
}
}