我有一个包含 2 个项目的解决方案(在 .NET Framework 4.7.2 中),每个项目都包含 Main() 并且独立运行。我为它们中的每一个创建了一个记录器,并且每个消息都被很好地记录在控制台或 Azure 日志中。但是只有一个进程的消息会被发送到 Loggly。而且我每个人都有 CloseAndFlush 。
当我单独(本地)调试这些项目中的任何一个时,他们会将消息发送到 Loggly。
关于这里可能出现什么问题以及如何将来自两个进程的消息发送到 Loggly 的任何想法?
项目工作1:
{
public class Program
{
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration().ReadFrom.AppSettings().CreateLogger();
Log.Information("Job1 Starting...");
Log.Information("2nd line ..");
Log.Information("third line ..");
Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg));
Console.WriteLine("Job1 Starting...");
try
{
Install();
while (!IsExists)
{
Execute();
Thread.Sleep(1000);
}
}
finally
{
Log.CloseAndFlush();
}
}
public static void Execute()
{
Log.Information("Executing Job1 ...");
... some code here ...
}
}
}
项目工作2:
{
public class Program
{
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration().ReadFrom.AppSettings().CreateLogger();
Log.Information("Job2 Starting...");
Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg));
Console.WriteLine("Job2 Starting...");
try
{
Install();
var task = Execute();
task.Wait();
}
finally
{
Log.CloseAndFlush();
}
}
public static async Task Execute()
{
Log.Information("Executing Job2 ...");
... some code here ...
}
}
}
Job1 的 App.config:
<appSettings>
<add key="serilog:minimum-level" value="Debug" />
<add key="serilog:using:Loggly" value="Serilog.Sinks.Loggly" />
<add key="serilog:write-to:Loggly" />
<add key="Loggly.ApplicationName" value="myapp" />
<add key="Loggly.CustomerToken" value="MyTokenXXX" />
<add key="Loggly.Tags" value="myapp,job1" />
</appSettings>
Job2 的 App.config:
<appSettings>
<add key="serilog:minimum-level" value="Debug" />
<add key="serilog:using:Loggly" value="Serilog.Sinks.Loggly" />
<add key="serilog:write-to:Loggly" />
<add key="Loggly.ApplicationName" value="myapp" />
<add key="Loggly.CustomerToken" value="MyTokenXXX" />
<add key="Loggly.Tags" value="myapp,job2" />
</appSettings>
为这两个项目安装的 NuGet 包:
- Serilog v2.10.0
- Serilog.Extensions.Logging v3.0.1
- Serilog.Settings.AppSettings v2.2.2
- Serilog.Settings.Configuration v3.3.0
- Serilog.Sinks.File v4.1.0
- Serilog.Sinks.Loggly v5.4.0
- Serilog.Sinks.PeriodicBatching v2.3.0
- Serilog.Sinks.RollingFile v3.3.0