{"id":5066,"date":"2024-01-13T19:29:58","date_gmt":"2024-01-13T11:29:58","guid":{"rendered":"https:\/\/www.kenpai.com\/cms\/5066\/"},"modified":"2024-01-13T19:29:58","modified_gmt":"2024-01-13T11:29:58","slug":"photon-server%e6%b8%b8%e6%88%8f%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%bb%8e%e9%9b%b6%e5%bc%80%e5%a7%8b%e5%ad%a6%e4%b9%a0%ef%bc%88%e4%ba%8c%ef%bc%89-log%e6%97%a5%e5%bf%97%e6%96%87%e4%bb%b6%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.kenpai.com\/cms\/5066\/","title":{"rendered":"Photon Server\u6e38\u620f\u670d\u52a1\u5668\u4ece\u96f6\u5f00\u59cb\u5b66\u4e60\uff08\u4e8c\uff09 Log\u65e5\u5fd7\u6587\u4ef6\u914d\u7f6e\u4e0e\u8f93\u51fa"},"content":{"rendered":"<\/p>\n<p>\u5728\u4e0a\u4e00\u7ae0\u6211\u4eec\u5b66\u4e60\u6709\u5173Photon Server\u7684\u914d\u7f6e\uff0c\u8fd9\u7ae0\u6211\u4eec\u5f00\u59cb\u5b66\u4e60Log\u65e5\u5fd7\u6587\u4ef6\u914d\u7f6e\u4e0e\u8f93\u51fa<\/p>\n<p style=\"text-align:\">\n<p><strong>\u4e00\u3001Log\u65e5\u5fd7\u7684\u6253\u5f00<\/strong><\/p>\n<p>\u5728Photon\u4e2d\u70b9\u51fbOpen Logs\u9009\u9879\uff0c\u6253\u5f00BareTail\u8f6f\u4ef6\uff0c\u76f8\u5f53\u4e8e\u4e00\u4e2a\u8bb0\u4e8b\u672c\uff0c\u7528\u4e8eLog\u65e5\u5fd7\u7684\u8f93\u51fa\u3002<\/p>\n<p>\u6253\u5f00\u4ee5\u540e\u7684\u754c\u9762<\/p>\n<p><strong>\u4e8c\u3001Log\u65e5\u5fd7\u7684\u8f93\u51fa<\/strong><\/p>\n<p>1.\u5f15\u7528log4net.dll \u548cExitGames.Logging.Log4Net.dll\uff0c\u4f4d\u4e8elib\u6587\u4ef6\u5939\u4e0b\u3002<\/p>\n<p>2.\u6dfb\u52a0\u914d\u7f6e\u6587\u4ef6\uff0c\u7531\u4e8e\u6709\u56fa\u5b9a\u7684\u683c\u5f0f\uff0c\u56e0\u6b64\u6211\u4eec\u5728src-serverMmoPhoton.MmoDemo.Server\u6587\u4ef6\u5939\u4e0b\u590d\u5236\u4e00\u4efdlog4net.config\u6587\u4ef6\u653e\u5728\u6211\u4eec\u9879\u76ee\u7684\u6839\u76ee\u5f55\u4e0b\uff0c\u4fee\u6539\u5c5e\u6027\u4e3a\u59cb\u7ec8\u590d\u5236\u3002<\/p>\n<p>\u914d\u7f6e\u6587\u4ef6\u8def\u5f84 Photon:ApplicationLogPath\uff0c\u4fee\u6539\u4e3a\u81ea\u5df1\u7684\u7a0b\u5e8f\u540dMyGame\u3002<\/p>\n<p>&lt;file type=&quot;log4net.Util.PatternString&quot; value=&quot;%property{Photon:ApplicationLogPath}\\\\\\\\MyGame.Server.log&quot; \/&gt;<\/p>\n<p>3.\u5728\u4e3b\u7c7bMyGameServer\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u9759\u6001\u53ea\u8bfb\u5b57\u6bb5log\u5e76\u521d\u59cb\u5316<\/p>\n<p>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 System.IO; using log4net.Config;  namespace MyGamePhotonServer {     \/\/\u6240\u6709\u7684server\u7aef \u4e3b\u7c7b\u90fd\u8981\u96c6\u6210\u81eaapplicationbase     public class MyGameServer:ApplicationBase     {         public static readonly ILogger log = LogManager.GetCurrentClassLogger();          \/\/\/ &lt;summary&gt;         \/\/\/ \u521a\u4e00\u4e2a\u5ba2\u6237\u7aef\u8bf7\u6c42\u8fde\u63a5\u7684          \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;param name=&quot;initRequest&quot;&gt;&lt;\/param&gt;         \/\/\/ &lt;returns&gt;&lt;\/returns&gt;         protected override PeerBase CreatePeer(InitRequest initRequest)         {             log.Info(&quot;\u4e00\u4e2a\u5ba2\u6237\u7aef\u8fde\u63a5\u8fc7\u6765\u4e86\u3002\u3002\u3002\u3002&quot;);             return new MyClientPeer(initRequest);         }          \/\/\/ &lt;summary&gt;         \/\/\/ \u521d\u59cb\u5316         \/\/\/ &lt;\/summary&gt;         protected override void Setup()         {             \/\/ \u65e5\u5fd7\u7684\u521d\u59cb\u5316             log4net.GlobalContext.Properties[&quot;Photon:ApplicationLogPath&quot;] = Path.Combine(                                                                     Path.Combine(this.ApplicationRootPath, &quot;bin_Win64&quot;), &quot;log&quot;);             FileInfo configFileInfo = new FileInfo( Path.Combine( this.BinaryPath ,&quot;log4net.config&quot;));             if (configFileInfo.Exists)             {                 LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);\/\/\u8ba9photon\u77e5\u9053\u4f7f\u7528\u7684\u662fLog4NetLog\u63d2\u4ef6                 XmlConfigurator.ConfigureAndWatch(configFileInfo);\/\/\u8ba9log4net\u8fd9\u4e2a\u63d2\u4ef6\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6             }              log.Info(&quot;\u521d\u59cb\u5316\u5b8c\u6210\uff01&quot;);         }          \/\/\/ &lt;summary&gt;         \/\/\/ server\u7aef\u5173\u95ed\u7684\u65f6\u5019         \/\/\/ &lt;\/summary&gt;         protected override void TearDown()         {             log.Info(&quot;\u670d\u52a1\u5668\u5e94\u7528\u5173\u95ed\u4e86&quot;);         }     } }<\/p>\n<p>\u8fd0\u884c\u540e\u7684\u65e5\u5fd7\u8f93\u51fa\u7ed3\u679c<\/p>\n<\/p>\n<p>\u66f4\u591a\u5173\u4e8e\u4e91\u670d\u52a1\u5668\uff0c<span class='wp_keywordlink'><a href=\"https:\/\/www.kenpai.com\/domain.html\" title=\"\u57df\u540d\u6ce8\u518c\" target=\"_blank\">\u57df\u540d<\/a><\/span>\u6ce8\u518c\uff0c\u865a\u62df\u4e3b\u673a\u7684\u95ee\u9898\uff0c\u8bf7\u8bbf\u95ee<span class='wp_keywordlink'><a href=\"https:\/\/www.kenpai.com\/\" title=\"\u57a6\u6d3e\u79d1\u6280\u5b98\u7f51\" target=\"_blank\">\u57a6\u6d3e\u79d1\u6280<\/a><\/span>\u5b98\u7f51\uff1a<span class='wp_keywordlink'><a href=\"https:\/\/www.kenpai.com\/\" title=\"\u57a6\u6d3e\u79d1\u6280\u5b98\u7f51\" target=\"_blank\">www.kenpai.com<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e0a\u4e00\u7ae0\u6211\u4eec\u5b66\u4e60\u6709\u5173Photon Server\u7684\u914d\u7f6e\uff0c\u8fd9\u7ae0\u6211\u4eec\u5f00\u59cb\u5b66\u4e60Log\u65e5\u5fd7\u6587\u4ef6\u914d\u7f6e\u4e0e\u8f93\u51fa\u4e00\u3001Log\u65e5\u5fd7\u7684\u6253\u5f00\u5728Photon\u4e2d\u70b9\u51fbOpen Logs<\/p>\n","protected":false},"author":2,"featured_media":446,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3322],"tags":[3938],"class_list":["post-5066","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ktougao","tag-photon-server-log"],"_links":{"self":[{"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/posts\/5066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/comments?post=5066"}],"version-history":[{"count":0,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/posts\/5066\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/media\/446"}],"wp:attachment":[{"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/media?parent=5066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/categories?post=5066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/tags?post=5066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}