0
votes

I have a .NET solution with two projects:

  • LoggingWebJob
  • LoggingWebSite

The first project is a .NET Core 3.1 Azure WebJob created by using the template in Visual Studio. I am publishing that WebJob to Azure by Visual Studio and its appearing in Azure and showing logs in the WebJobs Dashboard.

The other project is a .NET Core 3.1 MVC App. That is also deployed fine to Azure through Visual Studio.

In Azure I turned on App Service Logs in hope to see Log Stream for both Apps & see the logs in blob storage. I set the level Verbose for both Application FileSystem & Blob. However I am able to see the logs for LoggingWebSite, but not for LoggingWebJob in both filesystem & as files in blob storage.

This is my Program.cs file:

    class Program
    {
        static async Task Main(string[] args)
        {
            var builder = new HostBuilder();
            builder.ConfigureWebJobs(b =>
            {
                b.AddAzureStorageCoreServices();
                b.AddAzureStorage();
            });

            builder.ConfigureLogging((context, b) =>
            {
                b.AddConsole();
                b.add
            });

            var host = builder.Build();
            using (host)
            {
                await host.RunAsync();
            }
        }
    }

This is the function file of the WebJob where logs should be generated:

   public class Functions
    {
        public static void ProcessQueueMessage([QueueTrigger("webjobqueue")] string message, ILogger logger)
        {
            var ts = new TraceSource("Diagoutput");

            ts.TraceEvent(TraceEventType.Verbose, 1, $"ProcessQueueMessage verbose trace {message}");
            ts.TraceEvent(TraceEventType.Information, 1, $"ProcessQueueMessage info trace {message}");
            ts.TraceEvent(TraceEventType.Warning, 1, $"ProcessQueueMessage warn trace {message}");
            ts.TraceEvent(TraceEventType.Error, 1, $"ProcessQueueMessage err trace {message}");
            ts.TraceEvent(TraceEventType.Critical, 1, $"ProcessQueueMessage crit trace {message}");

            logger.LogInformation(message);

            Console.WriteLine($"ProcessQueueMessage Console {message}");
            Console.Error.WriteLine($"ProcessQueueMessage Console Error {message}");
        }
    }

So I am really wondering if Live Log Stream & Logs to blob are supported for WebJobs as part of App Service also? If so, what may be possible reasons for not seeing the logs?

1

1 Answers

0
votes

You should use Console Logging rather than App Service Logging in WebJobs. Here is a sample:

using Microsoft.Extensions.Logging;

#region snippet_LoggerFactory
class Program
{
    static void Main(string[] args)
    {
        using var loggerFactory = LoggerFactory.Create(builder =>
        {
            builder
                .AddFilter("Microsoft", LogLevel.Warning)
                .AddFilter("System", LogLevel.Warning)
                .AddFilter("LoggingConsoleApp.Program", LogLevel.Debug)
                .AddConsole()
                .AddEventLog();
        });
        ILogger logger = loggerFactory.CreateLogger<Program>();
        logger.LogInformation("Example log message");
    }
}
#endregion

And see the log file from kudu site: data -> jobs -> {your-job-type} -> {your-job-name}

The log file looks like this: enter image description here