问题
I have to create a text
file on linux
when the service is starting. I tried to keep IsOSPlatform
to recognize OS
and based on it, I have written code to create a text file for logs. Below is the code which not generating the file only for linux
, for windows
it creates a file.
public static void Main(string[] args)
{
bool isLinux = System.Runtime.InteropServices.RuntimeInformation
.IsOSPlatform(OSPlatform.Linux);
if(isLinux)
{
string sourceFile = System.IO.Path.Combine("~", "MyLog", "Config.xml");
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.File(sourceFile).CreateLogger();
}
else
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.File(@"C:\temp\Workerservice\logfile.txt").CreateLogger();
}
IHost host = CreateHostBuilder(args).Build();
host.Services.UseScheduler(scheduler =>
{
scheduler
.Schedule<ReprocessInvocable>()
.EveryThirtySeconds();
});
host.Run();
}
How can I get it work?
来源:https://stackoverflow.com/questions/62255952/in-workerservice-file-generation-not-working-only-for-linux-net-core