Add EnvelopeGenerator.Service as a .NET Worker Service
Introduced a new project `EnvelopeGenerator.Service` to the solution as a .NET Worker Service targeting the `net4.6.2` framework. - Configured the project with nullable reference types, implicit usings, and `LangVersion` set to `latest`. - Added a `Worker` class that logs periodic messages while running. - Updated `Program.cs` to configure and run the Worker Service. - Added `launchSettings.json` for development environment configuration. - Added `appsettings.json` and `appsettings.Development.json` for logging configuration. - Included the project in `EnvelopeGenerator.sln` with appropriate build configurations and hierarchy updates.
This commit is contained in:
14
EnvelopeGenerator.Service/EnvelopeGenerator.Service.csproj
Normal file
14
EnvelopeGenerator.Service/EnvelopeGenerator.Service.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net4.6.2</TargetFrameworks>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>dotnet-EnvelopeGenerator.Service-816256a4-c636-4313-92c0-b62b04040c2b</UserSecretsId>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
7
EnvelopeGenerator.Service/Program.cs
Normal file
7
EnvelopeGenerator.Service/Program.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using EnvelopeGenerator.Service;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
12
EnvelopeGenerator.Service/Properties/launchSettings.json
Normal file
12
EnvelopeGenerator.Service/Properties/launchSettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"EnvelopeGenerator.Service": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
EnvelopeGenerator.Service/Worker.cs
Normal file
24
EnvelopeGenerator.Service/Worker.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace EnvelopeGenerator.Service
|
||||
{
|
||||
public class Worker : BackgroundService
|
||||
{
|
||||
private readonly ILogger<Worker> _logger;
|
||||
|
||||
public Worker(ILogger<Worker> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (_logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
}
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
EnvelopeGenerator.Service/appsettings.Development.json
Normal file
8
EnvelopeGenerator.Service/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
8
EnvelopeGenerator.Service/appsettings.json
Normal file
8
EnvelopeGenerator.Service/appsettings.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user