Serilog文件接收器在从SQL作业中执行时不写入日志。

huangapple go评论52阅读模式
英文:

Serilog file sink not writing logging when executed from a sql job

问题

以下是您要翻译的内容:

The dilemma:

我已经为一个现有的控制台应用程序添加了日志记录,该应用程序通过SQL作业每5分钟执行一次。在我执行程序时,日志记录在开发、测试和生产中都能正常工作。但当应用程序从SQL作业中执行时,日志记录不会发生。尽管如此,每次由SQL作业运行时,应用程序似乎都能成功完成其任务。已验证运行SQL作业的帐户对日志文件夹具有写入权限。

The setup:

应用程序是一个运行在.NET 4.8框架上的控制台应用程序。

使用的Serilog NuGet包:

<package id="Serilog" version="2.12.0" targetFramework="net48" />
<package id="Serilog.Enrichers.Environment" version="2.2.0" targetFramework="net48" />
<package id="Serilog.Sinks.Console" version="4.1.0" targetFramework="net48" />
<package id="Serilog.Sinks.File" version="5.0.0" targetFramework="net48" />

Serilog配置:

public static void Main(string[] args)
{
    Log.Logger = new LoggerConfiguration()
        .Enrich.WithMachineName()
        .Enrich.WithEnvironmentUserName()
        .MinimumLevel.Debug()
        .WriteTo.Console()
        .WriteTo.File("logs/applicationName_.txt",
            rollingInterval: RollingInterval.Day,
            outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {MachineName} {EnvironmentUserName} | {Message}{NewLine}{Exception}")
        .CreateLogger();
    ...
}
英文:

The dilemma:

I've added logging to an existing console application for work that is executed every 5 minutes via a sql job. The logging has worked in development, testing, and production when I execute the program. The logging doesn't happen when the application is executed from a sql job. The application does appear to complete it's task successfully each time it is run by the sql job though. Write permissions for the account running the sql job to the log folder have been verified.

The setup:

Application is a console app on .net 4.8 framework.

Serilog nuget packages used:

&lt;package id=&quot;Serilog&quot; version=&quot;2.12.0&quot; targetFramework=&quot;net48&quot; /&gt;
&lt;package id=&quot;Serilog.Enrichers.Environment&quot; version=&quot;2.2.0&quot; targetFramework=&quot;net48&quot; /&gt;
&lt;package id=&quot;Serilog.Sinks.Console&quot; version=&quot;4.1.0&quot; targetFramework=&quot;net48&quot; /&gt;
&lt;package id=&quot;Serilog.Sinks.File&quot; version=&quot;5.0.0&quot; targetFramework=&quot;net48&quot; /&gt;

Serilog configuration:

public static void Main(string[] args)
{
	Log.Logger = new LoggerConfiguration()
		.Enrich.WithMachineName()
		.Enrich.WithEnvironmentUserName()
		.MinimumLevel.Debug()
		.WriteTo.Console()
		.WriteTo.File(&quot;logs/applicationName_.txt&quot;,
			rollingInterval: RollingInterval.Day,
			outputTemplate: &quot;{Timestamp:HH:mm:ss} [{Level:u3}] {MachineName} {EnvironmentUserName} | {Message}{NewLine}{Exception}&quot;)
		.CreateLogger();
	...

答案1

得分: 1

你应该将日志文件路径更改为绝对路径。

.WriteTo.File("C:\logs\applicationName.txt", 
英文:

You should change the log file path to be absolute.

.WriteTo.File(&quot;C:\logs\applicationName.txt&quot;,

huangapple
  • 本文由 发表于 2023年7月13日 22:41:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76680651.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定