mirror of
https://github.com/MeowCraftMC/CrystalConnector
synced 2025-05-22 02:43:00 +00:00
@@ -8,7 +8,26 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Spectre.Console" Version="0.47.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0-preview.7.23375.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0-preview.7.23375.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.7.23375.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0-preview.7.23375.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0-preview.7.23375.6" />
|
||||
<PackageReference Include="NLog" Version="5.2.4" />
|
||||
<PackageReference Include="NLog.Extensions.Hosting" Version="5.3.4" />
|
||||
<PackageReference Include="Spectre.Console" Version="0.47.1-preview.0.12" />
|
||||
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="config.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="NLog.config">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
|
||||
namespace CrystalConnector;
|
||||
|
||||
public class CrystalService : IHostedService
|
||||
{
|
||||
private ILogger<CrystalService> Logger { get; }
|
||||
private IConfiguration Config { get; }
|
||||
|
||||
public CrystalService(ILogger<CrystalService> logger, IConfiguration config, IHostApplicationLifetime appLifetime)
|
||||
{
|
||||
Logger = logger;
|
||||
Config = config;
|
||||
|
||||
appLifetime.ApplicationStarted.Register(OnStarted);
|
||||
appLifetime.ApplicationStopping.Register(OnStopping);
|
||||
appLifetime.ApplicationStopped.Register(OnStopped);
|
||||
}
|
||||
|
||||
private void OnStarted()
|
||||
{
|
||||
Logger.LogInformation("Starting!");
|
||||
}
|
||||
|
||||
private void OnStopping()
|
||||
{
|
||||
Logger.LogInformation("Stopping!");
|
||||
}
|
||||
|
||||
private void OnStopped()
|
||||
{
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
LogManager.Shutdown();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
throwConfigExceptions="true">
|
||||
<variable name="logLayout" value="[${longdate}][${logger}][${level}]${message:withexception=true}"/>
|
||||
<targets async="true">
|
||||
<target name="file"
|
||||
xsi:type="File"
|
||||
fileName="${basedir}/logs/${shortdate}.txt"
|
||||
keepFileOpen="false"
|
||||
archiveEvery="Day"
|
||||
archiveNumbering="Rolling"
|
||||
maxArchiveFiles="10"
|
||||
enableArchiveFileCompression="true"
|
||||
archiveFileName="${basedir}/logs/${shortdate}-{###}.zip"
|
||||
layout="${logLayout}"/>
|
||||
<target name="debugFile"
|
||||
xsi:type="File"
|
||||
deleteOldFileOnStartup="true"
|
||||
fileName="${basedir}/logs/debug.txt"
|
||||
keepFileOpen="false"
|
||||
layout="${logLayout}"/>
|
||||
<target name="console" xsi:type="ColoredConsole" encoding="utf-8" layout="${logLayout}">
|
||||
<highlight-row foregroundColor="DarkRed" condition="level == LogLevel.Fatal"/>
|
||||
<highlight-row foregroundColor="Red" condition="level == LogLevel.Error"/>
|
||||
<highlight-row foregroundColor="Yellow" condition="level == LogLevel.Warn"/>
|
||||
<highlight-row foregroundColor="White" condition="level == LogLevel.Info"/>
|
||||
<highlight-row foregroundColor="Cyan" condition="level == LogLevel.Debug"/>
|
||||
</target>
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Info" writeTo="file, console"/>
|
||||
<logger name="*" minlevel="Debug" writeTo="debugFile"/>
|
||||
</rules>
|
||||
</nlog>
|
||||
@@ -1 +1,27 @@
|
||||
Console.WriteLine("Hello, world!");
|
||||
using CrystalConnector;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.Services.AddHostedService<CrystalService>();
|
||||
|
||||
// builder.Services.AddSingleton<Bot>();
|
||||
|
||||
builder.Environment.ContentRootPath = Directory.GetCurrentDirectory();
|
||||
builder.Configuration.AddJsonFile("config.json", true)
|
||||
.AddJsonFile($"config.{builder.Environment.EnvironmentName}.json")
|
||||
.AddEnvironmentVariables(prefix: "CRYSTAL_")
|
||||
.AddCommandLine(args);
|
||||
|
||||
builder.Logging.ClearProviders()
|
||||
.SetMinimumLevel(LogLevel.Trace)
|
||||
.AddNLog();
|
||||
|
||||
using var host = builder.Build();
|
||||
|
||||
await host.RunAsync();
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user