0

I have a solution (in .NET Framework 4.7.2) that contains 2 projects, each of those contains Main() and is run independently. I have created a Logger for each of them, and the messages from each being recorded fine in the Console or the Azure Log. But only messages from one process are getting sent to the Loggly. And I have CloseAndFlush in each of them.

And when I debug any of those projects individually (locally) they would send the message to Loggly.

Any thoughts on what could be wrong here, and how to make messages from both processes be sent to Loggly?

Project Job1:

  {
    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 ...
        }
    }
  }

Project Job2:

  {
    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 ...
        }
    }
  }

App.config for Job1:

<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>

App.config for Job2:

<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 packages installed for both projects:

  • 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
KVN
  • 863
  • 1
  • 17
  • 35
  • 1
    You read the configuration from the config....but you haven't shown us the config. Nor have you explained what NuGet packages related to Serilogs are in your apps. That's essential info. – mason Oct 21 '21 at 00:15
  • Thanks. I just updated with this info. – KVN Oct 21 '21 at 00:26
  • Are the logs that do get sent to Loggly always coming from the same process? Or does it change depending on which one gets started first? – C. Augusto Proiete Oct 21 '21 at 00:31
  • Did you confirm the configuration file `AppName.exe.config` is present in the folder where the `AppName.exe` is located? – C. Augusto Proiete Oct 21 '21 at 00:32
  • They are always from the same process, they are from Job1 (although Job2 would normally run first). And I do not see the AppName.exe.config in any location for any of those projects. – KVN Oct 21 '21 at 00:32
  • If you don't see AppName.exe.config in any location for those projects...then how does the app get its configuration? Do both apps have the same DLLs, and none obviously missing from one? Have you verified your Loggly tokens are valid and configured correctly? – mason Oct 21 '21 at 01:17
  • Actually, I should correct myself on the part of my last statement. I looked into the wrong location (I checked it under the AppName/obj/Debug/ instead of AppName/bin/Debug locations). If I look under AppName/bin/Debug - then I do see AppName.exe.config for each of those apps/jobs – KVN Oct 21 '21 at 19:48

0 Answers0