После ответа: .NET Core 3 Worker Service Настройки Внедрение зависимостей
Я могу получить настройки в Debug или в Release, в классе Worker.cs, но при развертывании в качестве службы Windowsэти значения возвращаются как нуль
Worker.cs
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
private readonly ServiceSettings _serviceSettings;
private readonly ServiceConfigurations _serviceConfigurations;
public Worker(ILogger<Worker> logger, IOptions<ServiceConfigurations> serviceConfigurations, IOptions<ServiceSettings> serviceSettings)
{
_logger = logger;
_serviceConfigurations = serviceConfigurations.Value;
_logger.LogInformation($"Worker running at: {DateTime.Now}");
_serviceSettings = serviceSettings.Value;
string retornoPathLog = null;
string PathLog = _serviceSettings.PathLog;
if (!Directory.Exists(PathLog))
{
retornoPathLog = "Diretório de LOG " + PathLog;
Directory.CreateDirectory(PathLog);
}
//Configure Serilo for Logging
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.Enrich.FromLogContext()
.WriteTo.File(PathLog + "log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
if (string.IsNullOrEmpty(retornoPathLog) == false)
{
Log.Information("[WFoneService - Watch Event] " + retornoPathLog);
}
}
}
appsettings.json:
{
"ConnectionStrings": {
"WFoneConnection": ""
},
"ServiceConfigurations": {
"UrlSignalrNotification": "urlValue",
"WatchIp": "ipValue",
"WatchPort": "portValue"
},
"ServiceSettings": {
"PathLog": "C:\\Log\\"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}