Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be5067e
commit 37fe0ff
Showing
7 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29230.61 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsServiceSample", "WindowsServiceSample\WindowsServiceSample.csproj", "{26B73191-83FD-4BC4-BEFE-184A742EE0F1}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{26B73191-83FD-4BC4-BEFE-184A742EE0F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{26B73191-83FD-4BC4-BEFE-184A742EE0F1}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{26B73191-83FD-4BC4-BEFE-184A742EE0F1}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{26B73191-83FD-4BC4-BEFE-184A742EE0F1}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {9A34D350-B0F2-4A67-9222-9442881FF13C} | ||
EndGlobalSection | ||
EndGlobal |
26 changes: 26 additions & 0 deletions
26
DotnetCore/WindowsServiceSample/WindowsServiceSample/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging.EventLog; | ||
|
||
namespace WindowsServiceSample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureServices((hostContext, services) => | ||
{ | ||
services.AddHostedService<Worker>() | ||
.Configure<EventLogSettings>(config => | ||
{ | ||
config.LogName = "My Log"; | ||
config.SourceName = "My Source"; | ||
}); | ||
}).UseWindowsService(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
DotnetCore/WindowsServiceSample/WindowsServiceSample/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"profiles": { | ||
"WindowsServiceSample": { | ||
"commandName": "Project", | ||
"environmentVariables": { | ||
"DOTNET_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
DotnetCore/WindowsServiceSample/WindowsServiceSample/WindowsServiceSample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
<UserSecretsId>dotnet-WindowsServiceSample-86566739-9A6B-44BC-9776-B39865E786CF</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0-preview9.19423.4" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="3.0.0-preview9.19423.4" /> | ||
</ItemGroup> | ||
</Project> |
29 changes: 29 additions & 0 deletions
29
DotnetCore/WindowsServiceSample/WindowsServiceSample/Worker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace WindowsServiceSample | ||
{ | ||
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) | ||
{ | ||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); | ||
await Task.Delay(1000, stoppingToken); | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
DotnetCore/WindowsServiceSample/WindowsServiceSample/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
DotnetCore/WindowsServiceSample/WindowsServiceSample/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |