수정중인 페이지 입니다.
server | v5 switch to v4  

Logging

목차

If you are running a local Photon Server and noticed a bad event rate then this is most likely caused by logging. For instance, we noticed that enabling both Photon Server logging and Windows Defender may cause the event rate to slow down considerably. That is why we recommend disabling all virus scanners and firewalls when enabling Photon logging so you can have the expected events rate. You can re-enable the virus scanners and firewalls once you stop logging on Photon Servers.

Logging Framework

Photon uses log4net as a logging framework.

Documentation: https://logging.apache.org/log4net/

메인 화면으로

Log Files And Locations

There are 3 types of log files:

The Unmanaged Photon Socket Server Log

  • Content: Written by the unmanaged "PhotonSocketServer.exe" core. All status messages from Photon's start / stop sequence are logged here, as well as exceptions from the native core (like: bugs in Photon itself, serialization errors from invalid client data and so on).
  • Name: "Photon-{InstanceName}-Timestamp.log"
  • Log Level Configuration: n/a
  • Location: Default is "/bin_WinXXX/log". To change the log file location set the "LogFileLocation" attribute on each Instance node in "PhotonServer.config". The "LogFileLocation" can be either an absolute path or relative to "PhotonSocketServer.exe".

Example:


<Default
    MinimumTimeout="5000"
    MaximumTimeout="30000"
    LogFileLocation="..\MyLogFolder"
>

메인 화면으로

The Managed CLR Log

  • Content: Written by the managed .NET runtime that hosts your application. All status messages from the CLR are logged here (for example: information about loaded .NET applications & assemblies) and ALL unhandled exceptions from your custom .NET applications.
  • Name: "PhotonCLR.log"
  • Log Level Configuration: configure the appropriate log4net appender in "/deploy/bin_WinXXX/Photon.local.log4net".
  • Location: Default is "/bin_WinXXX/log". To change the log file location configure the appropriate log4net appender in "/deploy/bin_WinXXX/Photon.local.log4net". You can use the "Photon:UnmanagedLogDirectory" property, which contains the value of the "LogFileLocation" attribute from "PhotonServer.config".

Example:


<appender name="A1" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="%property{Photon:UnmanagedLogDirectory}\\PhotonCLR.log" />            
    <!-- snip -->
</appender>

메인 화면으로

The Application Logs

  • Content: each .NET application that is hosted by Photon writes its own application log file. It contains all debug output from the application.
  • Name: "{MyApplication}.log".
  • Log Level Configuration: You can configure the appropriate log4net appender in "/deploy/{MyApplication}/bin/log4net.config".
  • Location: Default is "/deploy/log". To change the log file location configure the appropriate log4net appender in "/deploy/{MyApplication}/bin/log4net.config". You can use the "Photon:ApplicationLogPath" property, which is set to "/deploy/log" per default which can be changed in the Setup() method of your application.
protected override void Setup()
{
    // log4net
    log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(this.ApplicationRootPath, "log");
    var configFileInfo = new FileInfo(Path.Combine(this.BinaryPath, "log4net.config"));
    if (configFileInfo.Exists)
    {
        LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
        XmlConfigurator.ConfigureAndWatch(configFileInfo);
    }
}
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="true" update="Overwrite"> 
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
        <file type="log4net.Util.PatternString" value="%property{Photon:ApplicationLogPath}\\{MyApplication}.log" />    
        <!-- snip --> 
    </appender>
    <root>
        <!-- <level value="INFO" /> -->
        <!-- <level value="DEBUG" /> -->
        <level value="ALL" />
        <appender-ref ref="LogFileAppender" /> 
    </root>
</log4net>

메인 화면으로

Frequently Asked Questions

클라이언트가 연결하거나 연결을 끊을 때마다 로그는 어떻게 생성하나요?

어플리케이션의 "log4net.config"에 아래 내용을 추가합니다:


<logger name="Photon.SocketServer.ApplicationBase">
    <level value="DEBUG"/>
</logger>

"{MyApplication}.log"의 출력내용:

Successful connect:

2013-05-02 11:19:02,506 [23] DEBUG Photon.SocketServer.ApplicationBase [(null)] - OnInit - ConnID=17, IP 127.0.0.1 on port 4530
2013-05-02 11:19:02,506 [23] DEBUG Photon.SocketServer.ApplicationBase [(null)] - OnInit - response sent to ConnId 17 with SendResult Ok

Disconnect:

2013-05-02 11:19:07,608 [24] DEBUG Photon.SocketServer.ApplicationBase [(null)] - OnDisconnect - ConnID=17

메인 화면으로

Photon이 클라이언트에 작업 응답을 보낼 때 어떻게 로그를 생성하나요?

어플리케이션의 "log4net.config"에 아래 내용을 추가합니다:


<logger name="Photon.SocketServer.PeerBase">
    <level value="DEBUG"/>
</logger>

"{MyApplication}.log"을 출력내용:

2013-05-02 11:19:02,569 [21] DEBUG Photon.SocketServer.PeerBase [(null)] - SentOpResponse: ConnID=17, opCode=255, return=0, ChannelId=0 result=Ok size=14 bytes

메인 화면으로

How To Write A Log Entry When Photon Receives An Operation Request From A Client?

This kind of logging is best done in your application's Peer class (which inherits from HivePeer).


<logger name="Photon.Hive.HivePeer">
    <level value="DEBUG"/>
</logger>

Output from "{MyApplication}.log":

2013-05-02 11:19:02,553 [21] DEBUG Photon.Hive.HivePeer [(null)] - OnOperationRequest. Code=255

OnOperationRequest 메소드에서 로그 항목의 내용을 변경할 수 있습니다.

protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
    if (log.IsDebugEnabled)
    {
        log.DebugFormat("OnOperationRequest. Code={0}", operationRequest.OperationCode);
    }    
    // snip
}

메인 화면으로

클라이언트들이 왜 연결이 끊어질까요? 타임아웃은 어떻게 디버깅을 하나요?

클라이언트의 연결이 끊기는 이유를 확인하려면 피어에서 OnDisconnect가 호출될 때 디버그 로그 항목을 작성하도록 어플리케이션을 구성합니다.


<logger name="Photon.Hive.HivePeer">
    <level value="DEBUG"/>
</logger>

Peer 클래스(HivePeer에서 상속됨)에서 , OnDisconnect() 메소드는 다음의 코드와 같아야합니다:

protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
{
    if (log.IsDebugEnabled)
    {
        log.DebugFormat("OnDisconnect: conId={0}, reason={1}, reasonDetail={2}", this.ConnectionId, reasonCode, reasonDetail);
    }
    //     
}

"{MyApplication}.log"의 출력 내용:

2013-05-02 11:19:07,639 [12] DEBUG Photon.Hive.HivePeer [(null)] - OnDisconnect: conId=17, reason=ClientDisconnect, reasonDetail=

If you are using UDP: in case of "TimeoutDisconnect", the "reasonDetail" will contain the RoundTripTime history, like this:

index - sequence - rtt - variance - sentTime - recvTime - cmd_rtt

0 - 326 - 0 - 0 - 830717056 - 830728351 - 11295
1 - 325 - 89 - 19 - 830715918 - 830716042 - 124
2 - 324 - 85 - 14 - 830714826 - 830714904 - 78
3 - 323 - 86 - 17 - 830712751 - 830712813 - 62
4 - 322 - 89 - 14 - 830711659 - 830711737 - 78
5 - 321 - 90 - 16 - 830710551 - 830710645 - 94
6 - 320 - 90 - 19 - 830709428 - 830709537 - 109
7 - 319 - 88 - 19 - 830708320 - 830708414 - 94
8 - 318 - 88 - 23 - 830707197 - 830707306 - 109
9 - 317 - 86 - 24 - 830706105 - 830706183 - 78
10 - 316 - 87 - 29 - 830704701 - 830704763 - 62
... etc ...

각 라인은 다음들의 값으로 구성되어 있습니다:

  • 인덱스 (0...49, 0이 가장 최신이고 49는 가장 오래된 것입니다. 최신의 50개 항목만 보여집니다.)
  • 시퀀스 - 증가하는 일련번호
  • rtt (RoundTripTime - ms로 현재 RTT - ACK 또는 타임아웃이 발생 처리된 이후 사용가능)
  • variance (ms 로 현재 Variance)
  • sentTime (명령이 전송된 시간)
  • recvTime (ACK가 수신된 시간)
  • cmd_rtt (ms 단위로 명령이 전송되고 ACK가 수신된 시간 사이의 간격)

위의 예에서 클라이언트는 62ms에서 124ms 사이에 cmd_rtt를 가지고 있었습니다. 마지막 명령에 대해 11초 동안 ACK를 수신하지 않은 후 연결이 끊어졌습니다.

기술문서 TOP으로 돌아가기