Skip to content

Commit 96dc970

Browse files
Merge pull request #29 from Chris-Wolfgang/develop
Created Template for Both CLI and VS
2 parents b8e44cc + 3f721f3 commit 96dc970

17 files changed

+797
-100
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "http://json.schemastore.org/vs-2017.3.host",
3+
"icon": "icon.png",
4+
"symbolInfo": [
5+
{
6+
"id": "AuthorName",
7+
"name": {
8+
"text": "Author Name"
9+
},
10+
"isVisible": "true"
11+
},
12+
{
13+
"id": "Description",
14+
"name": {
15+
"text": "Description"
16+
},
17+
"isVisible": "true"
18+
}
19+
]
20+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/template",
3+
"author": "Chris Wolfgang",
4+
"classifications": [ "Console" ],
5+
"identity": "Wolfgang.Preconfigured.Console",
6+
"name": "Wolfgang Preconfigured Console App",
7+
"shortName": "wpconsole",
8+
"sourceName": "ConsoleAppTemplate",
9+
"description": "A console application preconfigured with additional package including McMaster's CommandLineUtils, Serilog and others'",
10+
"defaultName": "ConsoleApp",
11+
"tags": {
12+
"language": "C#",
13+
"type": "project"
14+
},
15+
"postActions": [
16+
{
17+
"description": "Run package upgrade",
18+
"manualInstructions": [
19+
{
20+
// TODO run a CLI to upgrade packages
21+
"text": "Review the ReadMe.md file in the root of the project for a descrption of the project and next steps"
22+
}
23+
],
24+
"actionId": "AC1156F7-BB77-4DB8-B28F-24EEBCCA1E5C",
25+
"continueOnError": true
26+
},
27+
{
28+
"description": "Review ReadMe.md",
29+
"manualInstructions": [
30+
{
31+
"text": "Review the ReadMe.md file in the root of the project for a descrption of the project and next steps"
32+
}
33+
],
34+
"actionId": "AC1156F7-BB77-4DB8-B28F-24EEBCCA1E5C",
35+
"continueOnError": true
36+
}
37+
]
38+
}
Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,87 @@
1-
// TODO If you are using UseMultiEnvironment then you can delete this file
2-
1+
// TODO If you are using UsSingleEnvironment then you can delete this file
32
{
43
// TODO : Add your connection strings here
54
"ConnectionStrings": {
65

76
},
7+
"Serilog": {
8+
// TODO : Specifiy the where logs should be written to. You can add additional sinks and remove the ones you don't need.
9+
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
10+
11+
// TODO : Specify the minimum level for all logger logs to be written.
12+
// Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
13+
"MinimumLevel": {
14+
// TODO : Specify the minimum level for all logger logs to be written.
15+
// Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
16+
"Default": "Verbose",
17+
18+
// Override the minimum level for specific namespaces or classes
19+
"Override": {
20+
// Log messages from the Microsoft namespace at the Warning level or higher. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
21+
"Microsoft": "Warning",
22+
23+
// Log messages from the System namespace at the Warning level or higher. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
24+
"System": "Warning"
25+
}
26+
},
27+
28+
"WriteTo": [
29+
{
30+
"Name": "Console",
31+
"Args": {
32+
// Sets the format of log entries
33+
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
34+
35+
// Sets the minimum level for the console sink. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
36+
"restrictedToMinimumLevel": "Information"
37+
}
38+
},
39+
{
40+
// File sink configuration
41+
"Name": "File",
42+
"Args": {
43+
// TODO Specify the location for the logs files
44+
"path": "logs/log-.txt",
45+
46+
// When true will create a new file is the current file size exceeds the fileSizeLimitBytes
47+
"rollOnFileSizeLimit": true,
48+
49+
// Creates a new file everyday
50+
"rollingInterval": "Day",
51+
52+
// Sets the maximum size of the log file in bytes
53+
"fileSizeLimitBytes": "1000000",
54+
55+
// Sets the format of log entries
56+
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
57+
58+
// Sets the minimum level for the file sink. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
59+
"restrictedToMinimumLevel": "Verbose"
60+
}
61+
}
62+
],
63+
"Enrich": [
64+
// Routes framework log messages through Serilog, so you can get information about the framework's internal operations.
65+
"FromLogContext",
66+
67+
// Adds MachineName based on either %COMPUTERNAME% (Windows) or $HOSTNAME (macOS, Linux)
68+
// "WithMachineName",
69+
70+
// Adds EnvironmentName based on ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT
71+
"WithEnvironmentName"
72+
73+
// Adds EnvironmentUserName based on USERNAME and USERDOMAIN
74+
//"WithEnvironmentUserName",
75+
]
76+
},
77+
878
// TODO : Add your app settings here creating multiple sections as necessary
979
"SampleConfiguration": {
1080
"CommandTimeout": 1000
81+
},
82+
// TODO : Add your app settings here creating multiple sections as necessary
83+
"Properties": {
84+
// TODO : Replace with your application name from template
85+
"Application": "Sample"
1186
}
1287
}

ConsoleAppTemplate/ConsoleAppTemplate/AppSettings.Production.json

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,84 @@
55
"ConnectionStrings": {
66

77
},
8+
"Serilog": {
9+
// TODO : Specifiy the where logs should be written to. You can add additional sinks and remove the ones you don't need.
10+
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
11+
12+
// TODO : Specify the minimum level for all logger logs to be written.
13+
// Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
14+
"MinimumLevel": {
15+
// TODO : Specify the minimum level for all logger logs to be written.
16+
// Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
17+
"Default": "Information",
18+
19+
// Override the minimum level for specific namespaces or classes
20+
"Override": {
21+
// Log messages from the Microsoft namespace at the Warning level or higher. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
22+
"Microsoft": "Warning",
23+
24+
// Log messages from the System namespace at the Warning level or higher. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
25+
"System": "Warning"
26+
}
27+
},
28+
29+
"WriteTo": [
30+
{
31+
"Name": "Console",
32+
"Args": {
33+
// Sets the format of log entries
34+
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
35+
36+
// Sets the minimum level for the console sink. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
37+
"restrictedToMinimumLevel": "Warning"
38+
}
39+
},
40+
{
41+
// File sink configuration
42+
"Name": "File",
43+
"Args": {
44+
// TODO Specify the location for the logs files
45+
"path": "logs/log-.txt",
46+
47+
// When true will create a new file is the current file size exceeds the fileSizeLimitBytes
48+
"rollOnFileSizeLimit": true,
49+
50+
// Creates a new file everyday
51+
"rollingInterval": "Day",
52+
53+
// Sets the maximum size of the log file in bytes
54+
"fileSizeLimitBytes": "1000000",
55+
56+
// Sets the format of log entries
57+
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
58+
59+
// Sets the minimum level for the file sink. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
60+
"restrictedToMinimumLevel": "Information"
61+
}
62+
}
63+
],
64+
"Enrich": [
65+
// Routes framework log messages through Serilog, so you can get information about the framework's internal operations.
66+
"FromLogContext",
67+
68+
// Adds MachineName based on either %COMPUTERNAME% (Windows) or $HOSTNAME (macOS, Linux)
69+
// "WithMachineName",
70+
71+
// Adds EnvironmentName based on ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT
72+
"WithEnvironmentName"
73+
74+
// Adds EnvironmentUserName based on USERNAME and USERDOMAIN
75+
//"WithEnvironmentUserName",
76+
]
77+
},
78+
879
// TODO : Add your app settings here creating multiple sections as necessary
980
"SampleConfiguration": {
10-
"CommandTimeout": 2000
81+
"CommandTimeout": 1000
82+
},
83+
// TODO : Add your app settings here creating multiple sections as necessary
84+
"Properties": {
85+
// TODO : Replace with your application name from template
86+
"Application": "Sample"
1187
}
1288
}

ConsoleAppTemplate/ConsoleAppTemplate/AppSettings.json

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,85 @@
33
// TODO : Add your connection strings here
44
"ConnectionStrings": {
55

6+
},
7+
"Serilog": {
8+
// TODO : Specifiy the where logs should be written to. You can add additional sinks and remove the ones you don't need.
9+
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
10+
11+
// TODO : Specify the minimum level for all logger logs to be written.
12+
// Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
13+
"MinimumLevel": {
14+
// TODO : Specify the minimum level for all logger logs to be written.
15+
// Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
16+
"Default": "Debug",
17+
18+
// Override the minimum level for specific namespaces or classes
19+
"Override": {
20+
// Log messages from the Microsoft namespace at the Warning level or higher. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
21+
"Microsoft": "Warning",
22+
23+
// Log messages from the System namespace at the Warning level or higher. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
24+
"System": "Warning"
25+
}
26+
},
27+
28+
"WriteTo": [
29+
{
30+
"Name": "Console",
31+
"Args": {
32+
// Sets the format of log entries
33+
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
34+
35+
// Sets the minimum level for the console sink. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
36+
"restrictedToMinimumLevel": "Warning"
37+
}
38+
},
39+
{
40+
// File sink configuration
41+
"Name": "File",
42+
"Args": {
43+
// TODO Specify the location for the logs files
44+
"path": "logs/log-.txt",
45+
46+
// When true will create a new file is the current file size exceeds the fileSizeLimitBytes
47+
"rollOnFileSizeLimit": true,
48+
49+
// Creates a new file everyday
50+
"rollingInterval": "Day",
51+
52+
// Sets the maximum size of the log file in bytes
53+
"fileSizeLimitBytes": "1000000",
54+
55+
// Sets the format of log entries
56+
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
57+
58+
// Sets the minimum level for the file sink. Possible values are: Verbose, Debug, Information, Warning, Error, Fatal
59+
"restrictedToMinimumLevel": "Debug"
60+
}
61+
}
62+
],
63+
"Enrich": [
64+
// Routes framework log messages through Serilog, so you can get information about the framework's internal operations.
65+
"FromLogContext",
66+
67+
// Adds MachineName based on either %COMPUTERNAME% (Windows) or $HOSTNAME (macOS, Linux)
68+
// "WithMachineName",
69+
70+
// Adds EnvironmentName based on ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT
71+
"WithEnvironmentName",
72+
73+
// Adds EnvironmentUserName based on USERNAME and USERDOMAIN
74+
//"WithEnvironmentUserName",
75+
]
76+
},
77+
78+
// TODO : Add your app settings here creating multiple sections as necessary
79+
"Properties": {
80+
// TODO : Replace with your application name from template
81+
"Application": "Sample"
682
},
783
// TODO : Add your app settings here creating multiple sections as necessary
884
"SampleConfiguration": {
985
"CommandTimeout": 100
10-
}
86+
}
1187
}
7.68 KB
Loading

ConsoleAppTemplate/ConsoleAppTemplate/Command/SampleCommand.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.ComponentModel.DataAnnotations;
2+
using ConsoleAppTemplate.Model;
23
using McMaster.Extensions.CommandLineUtils;
4+
using Microsoft.Extensions.Logging;
35

46
namespace ConsoleAppTemplate.Command;
57

@@ -52,10 +54,44 @@ internal class SampleCommand
5254

5355
[Option
5456
(
55-
Description = "If set, the program will not send an email when complete"
57+
Description = "When specified, sends an email notification to the specified address"
5658
)
5759
]
5860
[EmailAddress]
5961
[MaxLength(255)]
60-
public string? NotifyUponComplete { get; set; }
62+
public string? EmailAddress { get; set; }
63+
64+
65+
internal async Task<int> OnExecuteAsync
66+
(
67+
SampleConfiguration configuration,
68+
IConsole console,
69+
IReporter reporter,
70+
ILogger<SampleCommand> logger
71+
)
72+
{
73+
logger.LogInformation("Starting {command}", GetType().Name);
74+
75+
try
76+
{
77+
// TODO Add your code here to process the command line arguments
78+
// TODO You can use the reporter to write to the console
79+
console.WriteLine("Hello world!");
80+
console.WriteLine($"CommandTimeout: {configuration.CommandTimeout}");
81+
reporter.Warn("Sample console warning");
82+
83+
logger.LogWarning("Sample log warning");
84+
}
85+
catch (Exception e)
86+
{
87+
logger.LogCritical(e, e.Message);
88+
console.WriteLine(e);
89+
return ExitCode.ApplicationError;
90+
}
91+
92+
93+
logger.LogInformation("Completed {command}", GetType().Name);
94+
95+
return ExitCode.Success;
96+
}
6197
}

0 commit comments

Comments
 (0)