-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
This issue has been moved from a ticket on Developer Community.
[severity:It's more difficult to complete my work]
I have create a .net core 3.1 API project and am hosting this in a Windows Service (windows 10 latest).
When I start my project from Visual Studio, my API runs as a console application and performs the configured API functionality and logging without problem. When I register that same .exe as a windows service, the service will not start. When I remove serilog configuration from the Main method in Program.cs file, the windows service starts and works as expected. Specifically, when I comment out the line "var config = builder. Build();" and republish the project, my service will start normally. Any help would be much appreciated.
public static void Main(string[] args)
{
var builder = new ConfigurationBuilder();
BuildConfig(builder);
var config = builder. Build();
string logdbPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\EPDAPI\log.db";
Log.Logger = new LoggerConfiguration()
. ReadFrom.Configuration(config)
. Enrich.FromLogContext()
. WriteTo.SQLite(logdbPath)
. CreateLogger();
Log.Logger.Information("Application Starting");
EnableDapperCustomTypeHandlers();
CreateHostBuilder(args)
. UseWindowsService()
. UseSerilog()
. Build()
. Run();
}
public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
. ConfigureServices((context, services) =>
{
services. AddSingleton<ISQLiteDataAccess, SQLiteDataAccess>();
services. AddSingleton<IContactData, ContactData>();
services. Configure(context. Configuration.GetSection("Kestrel"));
})
. ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions =>
{
// Set properties and call methods on options
})
. UseStartup();
});
}
static void BuildConfig(IConfigurationBuilder builder)
{
builder. SetBasePath(Directory.GetCurrentDirectory())
. AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
. AddJsonFile($"appsettings.{ Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
. AddEnvironmentVariables();
}
my appsettings.json file contains a small section on serilog
"Serilog": {
"MinimumLevel": "Information",
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
},
Original Comments
Feedback Bot on 10/2/2020, 05:21 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Feedback Bot on 10/8/2020, 11:36 PM:
Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem?view=vs-2019#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.
Original Solutions
(no solutions)