提交示例代码
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<!-- 物理复制 NLog 配置文件到项目根目录 -->
|
||||
<Target Name="CopyNLogFilesToProject" BeforeTargets="PrepareForBuild">
|
||||
<ItemGroup>
|
||||
<!-- 定义源文件路径,指向 NuGet 包中的文件 -->
|
||||
<FilesToCopy Include="$(MSBuildThisFileDirectory)..\build\NLog.config" />
|
||||
<FilesToCopy Include="$(MSBuildThisFileDirectory)..\build\NLog.xsd" />
|
||||
</ItemGroup>
|
||||
<!-- 仅当目标文件不存在时才执行复制操作 -->
|
||||
<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="$(MSBuildProjectDirectory)" Condition="!Exists('$(MSBuildProjectDirectory)\NLog.config')" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="$(MSBuildProjectDirectory)" Condition="!Exists('$(MSBuildProjectDirectory)\NLog.xsd')" SkipUnchangedFiles="true" />
|
||||
<ItemGroup>
|
||||
<!-- 使用 Include 确保文件在解决方案中显示 -->
|
||||
<None Include="$(MSBuildProjectDirectory)\NLog.config">
|
||||
<!-- 确保复制到输出目录,并设置复制模式 -->
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="$(MSBuildProjectDirectory)\NLog.xsd">
|
||||
<!-- 确保复制到输出目录,并设置复制模式 -->
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -0,0 +1,37 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageId>Fantasy-Net.NLog</PackageId>
|
||||
<PackageVersion>2024.1.20</PackageVersion>
|
||||
<Title>Fantasy-Net.NLog</Title>
|
||||
<Authors>qq362946</Authors>
|
||||
<owners>qq362946</owners>
|
||||
<PackageOutputPath>../../nupkg</PackageOutputPath>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<Description>
|
||||
Fantasy is a high-performance network development framework based on .NET, supporting mainstream protocols. It is designed for development teams or individuals needing a quick start, scalability, and a distributed, cross-platform solution at the commercial level. Fantasy aims to provide easy-to-use tools while ensuring high system performance and scalability.</Description>
|
||||
<Copyright>Copyright 2026 qq362946</Copyright>
|
||||
<PackageProjectUrl>https://www.code-fantasy.com/</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/qq362946/Fantasy</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>Net, c#, Server, Game, GameServer, Fantasy , Network</PackageTags>
|
||||
<PackageIcon>icon.png</PackageIcon>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyName>Fantasy-Net.NLog</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Fantasy-Net" Version="2024.2.22" />
|
||||
<PackageReference Include="NLog" Version="5.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="NLog.config" Pack="true" PackagePath="build\NLog.config" />
|
||||
<None Include="NLog.xsd" Pack="true" PackagePath="build\NLog.xsd" />
|
||||
<None Include="Fantasy-Net.NLog.targets" Pack="true" PackagePath="buildTransitive" />
|
||||
<None Include="icon.png" Pack="true" PackagePath="\"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -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>
|
||||
@@ -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
物品和背包的完整代码/Packages/Fantasy/Fantasy.Packages/Fantasy.NLog/NLog.xsd
Normal file
3483
物品和背包的完整代码/Packages/Fantasy/Fantasy.Packages/Fantasy.NLog/NLog.xsd
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 246 B |
Reference in New Issue
Block a user