@@ -21,6 +21,11 @@ namespace CodeCaster.PVBridge.Service
2121 /// </summary>
2222 public static class Program
2323 {
24+ /// <summary>
25+ /// Event Log source name.
26+ /// </summary>
27+ public static readonly string ApplicationName = "PVBridge Service" ;
28+
2429 public static async Task Main ( string [ ] args )
2530 {
2631 try
@@ -61,7 +66,7 @@ private static Command GetSyncCommand(IHost host)
6166 } ;
6267
6368 // TODO: make Argument<DateTime?>, but that doesn't work: https://github.com/dotnet/command-line-api/issues/1669
64- var untilOption = new Option < DateTime ? > ( new [ ] { "--until" , "-u" } , "The inclusive end date to sync. Format: yyyy-MM-dd." )
69+ var untilOption = new Option < DateTime ? > ( new [ ] { "--until" , "-u" } , "The inclusive end date to sync. Format: yyyy-MM-dd." )
6570 {
6671 IsRequired = false
6772 } ;
@@ -204,19 +209,13 @@ private static IHostBuilder CreateHostBuilder(string[] args)
204209 return Host . CreateDefaultBuilder ( args )
205210 . ConfigureAppConfiguration ( ( context , config ) =>
206211 {
207- config . AddEnvironmentVariables ( ) ;
208-
209- // enviroment from command line
210- // e.g.: dotnet run --environment "Staging"
211- config . AddCommandLine ( args ) ;
212-
213- config . AddJsonFile ( "appsettings.json" ) ;
214- config . AddJsonFile ( $ "appsettings.{ context . HostingEnvironment . EnvironmentName } .json", optional : true ) ;
212+ // Sets the Event Log source name (through UseWindowsServiceExtensions -> UseWindowsService).
213+ context . HostingEnvironment . ApplicationName = Program . ApplicationName ;
215214
215+ // Read "C:\ProgramData\PVBridge\PVBridge.AccountConfig.json". Optional because it doesn't exist on first run.
216216 var globalSettingsFilePath = ConfigurationReader . GlobalSettingsFilePath ;
217217 var globalSettingsFileName = Path . GetFileNameWithoutExtension ( ConfigurationReader . GlobalSettingsFilePath ) ;
218218
219- // Read "C:\ProgramData\PVBridge\PVBridge.AccountConfig.json". Optional because it doesn't exist on first run.
220219 config . AddJsonFile ( ConfigurationReader . GlobalSettingsFilePath , optional : true , reloadOnChange : true ) ;
221220 } )
222221 . ConfigureServices ( ( context , services ) =>
0 commit comments