提交 99a0005e 编写于 作者: T tanghai

根据不同的AppType和AppId,log打印到不同的文件中

上级 c217daa9
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="appType" value="" />
<variable name="appId" value="" />
<targets>
<target name="debug" xsi:type="File"
fileName="${basedir}/Log.Debug.txt"
fileName="${basedir}/Logs/Log-${var:appType}-${var:appId}-Debug.txt"
deleteOldFileOnStartup="true"
layout="${longdate} ${threadid:padCharacter=0:padding=4:fixedLength=true} ${message}" />
layout="${longdate} ${var:appType} ${var:appId} ${message}" />
</targets>
<targets>
<target name="error" xsi:type="File"
fileName="${basedir}/Log.Error.txt"
fileName="${basedir}/Logs/Log-${var:appType}-${var:appId}-Error.txt"
deleteOldFileOnStartup="false"
layout="${longdate} ${threadid:padCharacter=0:padding=4:fixedLength=true} ${message}" />
layout="${longdate} ${var:appType} ${var:appId} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="debug" />
......
using System;
using Base;
using Model;
using NLog;
using Object = Base.Object;
namespace App
......@@ -11,8 +12,6 @@ namespace App
{
try
{
Log.Info("server start........................");
BsonClassMapRegister.Register();
Object.ObjectManager.Register("Base", typeof(Game).Assembly);
......@@ -20,7 +19,11 @@ namespace App
Object.ObjectManager.Register("Controller", DllHelper.GetController());
StartConfig startConfig = Game.Scene.AddComponent<StartConfigComponent, string[]>(args).MyConfig;
LogManager.Configuration.Variables["appType"] = startConfig.Options.AppType;
LogManager.Configuration.Variables["appId"] = startConfig.Options.Id.ToString("D4");
Log.Info("server start........................");
Game.Scene.AddComponent<EventComponent>();
Game.Scene.AddComponent<TimerComponent>();
......
......@@ -37,6 +37,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
......
......@@ -5,7 +5,7 @@ namespace Base
{
public static class Log
{
private static readonly ILog globalLog = new NLogAdapter(new StackInfoDecorater());
private static readonly ILog globalLog = new NLogAdapter();
public static Dictionary<long, Action<LogType, string>> Callback { get; } = new Dictionary<long, Action<LogType, string>>();
......
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
......@@ -37,7 +38,7 @@ namespace Model
#if __MonoCS__
const string exe = @"mono";
const string exe = @"/usr/local/bin/mono";
string arguments = $"App.exe --id={startConfig.Options.Id} --appType={startConfig.Options.AppType}";
const string workDir = @"../Server/Bin/Debug";
#else
......@@ -45,18 +46,24 @@ namespace Model
string arguments = $"--id={startConfig.Options.Id} --appType={startConfig.Options.AppType}";
const string workDir = @"..\Server\Bin\Debug";
#endif
Log.Debug($"{startConfig.Options.Id} {MongoHelper.ToJson(startConfig)}");
ProcessStartInfo info = new ProcessStartInfo
try
{
FileName = exe,
Arguments = arguments,
CreateNoWindow = true,
UseShellExecute = true,
WorkingDirectory = workDir
};
ProcessStartInfo info = new ProcessStartInfo
{
FileName = exe,
Arguments = arguments,
CreateNoWindow = true,
UseShellExecute = true,
WorkingDirectory = workDir
};
Process process = Process.Start(info);
this.processes.Add(process.Id, process);
Process process = Process.Start(info);
this.processes.Add(process.Id, process);
}
catch (Exception e)
{
Log.Error(e.ToString());
}
}
}
}
......
......@@ -30,8 +30,15 @@ namespace Base
public TSocket(TPoller poller, string host, int port): this(poller)
{
this.Bind(host, port);
this.Listen(100);
try
{
this.Bind(host, port);
this.Listen(100);
}
catch (Exception e)
{
throw new Exception($"socket bind error: {host} {port}", e);
}
}
public Socket Socket
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册