饭太稀
This commit is contained in:
9
Main/Fantasy.json
Normal file
9
Main/Fantasy.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
38
Main/Main.csproj
Normal file
38
Main/Main.csproj
Normal file
@@ -0,0 +1,38 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
<LangVersion>default</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<OutputPath>../../Bin/Debug/</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<OutputPath>../../Bin/Release/</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Fantasy.Net\Fantasy.Net\Fantasy.Net.csproj" />
|
||||
<ProjectReference Include="..\Entity\Entity.csproj" />
|
||||
<ProjectReference Include="..\Hotfix\Hotfix.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="NLog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="NLog.xsd">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog" Version="5.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
91
Main/NLog.config
Normal file
91
Main/NLog.config
Normal file
@@ -0,0 +1,91 @@
|
||||
<?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"
|
||||
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
|
||||
<targets async="true">
|
||||
<target name="ServerDebug" xsi:type="File"
|
||||
encoding="UTF-8"
|
||||
createDirs="true"
|
||||
autoFlush="false"
|
||||
keepFileOpen="true"
|
||||
concurrentWrites="true"
|
||||
openFileCacheTimeout="30"
|
||||
openFileFlushTimeout="60"
|
||||
fileName="${basedir}/../Logs/Server/Server${date:format=yyyyMMdd}/${logger}.${var:appId}.${date:format=yyyyMMddHH}.Debug.log"
|
||||
layout="${longdate} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
|
||||
</targets>
|
||||
<targets async="true">
|
||||
<target name="ServerInfo" xsi:type="File"
|
||||
encoding="UTF-8"
|
||||
createDirs="true"
|
||||
autoFlush="false"
|
||||
keepFileOpen="true"
|
||||
concurrentWrites="true"
|
||||
openFileCacheTimeout="30"
|
||||
openFileFlushTimeout="60"
|
||||
fileName="${basedir}/../Logs/Server/Server${date:format=yyyyMMdd}/${logger}.${var:appId}.${date:format=yyyyMMddHH}.Info.log"
|
||||
layout="${longdate} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
|
||||
</targets>
|
||||
<targets async="true">
|
||||
<target name="ServerWarn" xsi:type="File"
|
||||
encoding="UTF-8"
|
||||
createDirs="true"
|
||||
autoFlush="false"
|
||||
keepFileOpen="true"
|
||||
concurrentWrites="true"
|
||||
openFileCacheTimeout="30"
|
||||
openFileFlushTimeout="60"
|
||||
fileName="${basedir}/../Logs/Server/Server${date:format=yyyyMMdd}/${logger}.${var:appId}.${date:format=yyyyMMddHH}.Warn.log"
|
||||
layout="${longdate} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
|
||||
</targets>
|
||||
<targets async="true">
|
||||
<target name="ServerError" xsi:type="File"
|
||||
encoding="UTF-8"
|
||||
createDirs="true"
|
||||
autoFlush="false"
|
||||
keepFileOpen="true"
|
||||
concurrentWrites="true"
|
||||
openFileCacheTimeout="30"
|
||||
openFileFlushTimeout="60"
|
||||
fileName="${basedir}/../Logs/Server/Server${date:format=yyyyMMdd}/${logger}.${var:appId}.${date:format=yyyyMMddHH}.Error.log"
|
||||
layout="${longdate} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
|
||||
</targets>
|
||||
<targets async="true">
|
||||
<target name="ServerTrace" xsi:type="File"
|
||||
encoding="UTF-8"
|
||||
createDirs="true"
|
||||
autoFlush="false"
|
||||
keepFileOpen="true"
|
||||
concurrentWrites="true"
|
||||
openFileCacheTimeout="30"
|
||||
openFileFlushTimeout="60"
|
||||
fileName="${basedir}/../Logs/Server/Server${date:format=yyyyMMdd}/${logger}.${var:appId}.${date:format=yyyyMMddHH}.Trace.log"
|
||||
layout="${longdate} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
|
||||
</targets>
|
||||
<targets async="true">
|
||||
<target name="ConsoleColor" xsi:type="ColoredConsole"
|
||||
useDefaultRowHighlightingRules="false"
|
||||
layout="${longdate} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}">
|
||||
<highlight-row condition="level == LogLevel.Debug" foregroundColor="DarkGreen" />
|
||||
<highlight-row condition="level == LogLevel.Info" foregroundColor="Gray" />
|
||||
<highlight-row condition="level == LogLevel.Warn" foregroundColor="Yellow" />
|
||||
<highlight-row condition="level == LogLevel.Error" foregroundColor="DarkRed" />
|
||||
<highlight-row condition="level == LogLevel.Fatal" foregroundColor="Red" />
|
||||
</target>
|
||||
</targets>
|
||||
<rules>
|
||||
<!-- 控制台 调试或编辑器启动的时候会调用-->
|
||||
<logger ruleName="ConsoleTrace" name="Server" level="Trace" writeTo="ConsoleColor" />
|
||||
<logger ruleName="ConsoleDebug" name="Server" level="Debug" writeTo="ConsoleColor" />
|
||||
<logger ruleName="ConsoleInfo" name="Server" level="Info" writeTo="ConsoleColor" />
|
||||
<logger ruleName="ConsoleWarn" name="Server" level="Warn" writeTo="ConsoleColor" />
|
||||
<logger ruleName="ConsoleError" name="Server" level="Error" writeTo="ConsoleColor" />
|
||||
<!-- 服务端日志输出文件 发布到服务器后会调用-->
|
||||
<logger ruleName="ServerDebug" name="Server" level="Debug" writeTo="ServerDebug" />
|
||||
<logger ruleName="ServerTrace" name="Server" level="Trace" writeTo="ServerTrace" />
|
||||
<logger ruleName="ServerInfo" name="Server" level="Info" writeTo="ServerInfo" />
|
||||
<logger ruleName="ServerWarn" name="Server" level="Warn" writeTo="ServerWarn" />
|
||||
<logger ruleName="ServerError" name="Server" level="Error" writeTo="ServerError" />
|
||||
</rules>
|
||||
</nlog>
|
||||
167
Main/NLog.cs
Normal file
167
Main/NLog.cs
Normal file
@@ -0,0 +1,167 @@
|
||||
using Fantasy.Platform.Net;
|
||||
using NLog;
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用 NLog 实现的日志记录器。
|
||||
/// </summary>
|
||||
public class NLog : ILog
|
||||
{
|
||||
private readonly Logger _logger; // NLog 日志记录器实例
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 NLog 实例。
|
||||
/// </summary>
|
||||
/// <param name="name">日志记录器的名称。</param>
|
||||
public NLog(string name)
|
||||
{
|
||||
// 获取指定名称的 NLog 日志记录器
|
||||
_logger = LogManager.GetLogger(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化方法
|
||||
/// </summary>
|
||||
/// <param name="processMode"></param>
|
||||
public void Initialize(ProcessMode processMode)
|
||||
{
|
||||
// 非Benchmark模式、根据不同的运行模式来选择日志的方式
|
||||
switch (processMode)
|
||||
{
|
||||
case ProcessMode.Develop:
|
||||
{
|
||||
LogManager.Configuration.RemoveRuleByName("ServerDebug");
|
||||
LogManager.Configuration.RemoveRuleByName("ServerTrace");
|
||||
LogManager.Configuration.RemoveRuleByName("ServerInfo");
|
||||
LogManager.Configuration.RemoveRuleByName("ServerWarn");
|
||||
LogManager.Configuration.RemoveRuleByName("ServerError");
|
||||
break;
|
||||
}
|
||||
case ProcessMode.Release:
|
||||
{
|
||||
LogManager.Configuration.RemoveRuleByName("ConsoleTrace");
|
||||
LogManager.Configuration.RemoveRuleByName("ConsoleDebug");
|
||||
LogManager.Configuration.RemoveRuleByName("ConsoleInfo");
|
||||
LogManager.Configuration.RemoveRuleByName("ConsoleWarn");
|
||||
LogManager.Configuration.RemoveRuleByName("ConsoleError");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录跟踪级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
public void Trace(string message)
|
||||
{
|
||||
_logger.Trace(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录警告级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
public void Warning(string message)
|
||||
{
|
||||
_logger.Warn(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录信息级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
public void Info(string message)
|
||||
{
|
||||
_logger.Info(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录调试级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
public void Debug(string message)
|
||||
{
|
||||
_logger.Debug(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录错误级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
public void Error(string message)
|
||||
{
|
||||
_logger.Error(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录严重错误级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
public void Fatal(string message)
|
||||
{
|
||||
_logger.Fatal(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录跟踪级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
public void Trace(string message, params object[] args)
|
||||
{
|
||||
_logger.Trace(message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录警告级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
public void Warning(string message, params object[] args)
|
||||
{
|
||||
_logger.Warn(message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录信息级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
public void Info(string message, params object[] args)
|
||||
{
|
||||
_logger.Info(message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录调试级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
public void Debug(string message, params object[] args)
|
||||
{
|
||||
_logger.Debug(message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录错误级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
public void Error(string message, params object[] args)
|
||||
{
|
||||
_logger.Error(message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录严重错误级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
public void Fatal(string message, params object[] args)
|
||||
{
|
||||
_logger.Fatal(message, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
3483
Main/NLog.xsd
Normal file
3483
Main/NLog.xsd
Normal file
File diff suppressed because it is too large
Load Diff
34
Main/Program.cs
Normal file
34
Main/Program.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Assembly;
|
||||
using Fantasy.ConfigTable;
|
||||
using Fantasy.DataBase;
|
||||
using Fantasy.Helper;
|
||||
using Fantasy.IdFactory;
|
||||
using Fantasy.Platform.Net;
|
||||
// 设置配置表的路径
|
||||
ConfigTableHelper.Initialize("../../../Config/Binary");
|
||||
// 设置ID生成规则
|
||||
IdFactoryHelper.Initialize(IdFactoryType.World);
|
||||
// 获取配置文件
|
||||
// 比如通过远程获取这个配置文件,这样可以多组服务器共享一套配置了
|
||||
var machineConfigText = await FileHelper.GetTextByRelativePath("../../../Config/Json/Server/MachineConfigData.Json");
|
||||
var processConfigText = await FileHelper.GetTextByRelativePath("../../../Config/Json/Server/ProcessConfigData.Json");
|
||||
var worldConfigText = await FileHelper.GetTextByRelativePath("../../../Config/Json/Server/WorldConfigData.Json");
|
||||
var sceneConfigText = await FileHelper.GetTextByRelativePath("../../../Config/Json/Server/SceneConfigData.Json");
|
||||
// 初始化配置文件
|
||||
// 如果重复初始化方法会覆盖掉上一次的数据,非常适合热重载时使用
|
||||
MachineConfigData.Initialize(machineConfigText);
|
||||
ProcessConfigData.Initialize(processConfigText);
|
||||
WorldConfigData.Initialize(worldConfigText);
|
||||
SceneConfigData.Initialize(sceneConfigText);
|
||||
// 注册日志模块到框架
|
||||
// 开发者可以自己注册日志系统到框架,只要实现Fantasy.ILog接口就可以。
|
||||
// 这里用的是NLog日志系统注册到框架中。
|
||||
Fantasy.Log.Register(new Fantasy.NLog("Server"));
|
||||
// 初始化框架,添加程序集到框架中
|
||||
await Fantasy.Platform.Net.Entry.Initialize(Fantasy.AssemblyHelper.Assemblies);
|
||||
// 启动Fantasy.Net
|
||||
await Fantasy.Platform.Net.Entry.Start();
|
||||
// 也可以使用下面的Start方法来初始化并且启动Fantasy.Net
|
||||
// 使用下面这个方法就不用使用上面的两个方法了。
|
||||
// await Fantasy.Platform.Net.Entry.Start(Fantasy.AssemblyHelper.Assemblies);
|
||||
10
Main/Properties/launchSettings.json
Normal file
10
Main/Properties/launchSettings.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"Main": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {},
|
||||
"commandLineArgs": "--m Develop"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user