Code: Select all
var processInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c sc create \"{envServiceName}\" binPath= \"\\\"{environmnetPath}\\publish\\MyApi.Api.exe\\\" --environment={environment}\" DisplayName= \"MyApi {environment} API Service\" start= auto",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = false
};
using var process = Process.Start(processInfo);
Code: Select all
builder.Host.UseSerilog((ctx, cfg) => cfg.ReadFrom.Configuration(ctx.Configuration));
Code: Select all
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "File",
"Args": {
"path": "D:\\deployments\\logs\\myapp\\log-.txt",
"rollingInterval": "Day"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName" ],
"Properties": {
"ApplicationName": "Your ASP.NET Core App"
}
},
"AllowedHosts": "*"
}
at serilog.extensions.logging.serilogLogger.log [TState] (Loglevel loglelevel, eventId EventID, TState -Status, Ausnahme -Ausnahme, Func`3 -Formatierer) class = "Lang-CS PrettyPrint-Override">
Code: Select all
dotnet publish --configuration Release --output publish --runtime win-x64 --self-contained=true
Code: Select all
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.WriteTo.Console()
.WriteTo.File(
path: Path.Combine("D:\\deployments\\logs\\myapp", "log-.txt"),
rollingInterval: RollingInterval.Day,
shared: true // Important for services
)
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.Enrich.WithProperty("ApplicationName", "Your ASP.NET Core App")
.CreateLogger();
Log.Information("Environment:" + builder.Environment.EnvironmentName);
builder.Host.UseWindowsService();
builder.Host.UseSerilog(Log.Logger);