Skip to content

UseSerilog() disables logging to Azure Diagnostics LogStream #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pcreyght opened this issue Mar 13, 2018 · 5 comments
Closed

UseSerilog() disables logging to Azure Diagnostics LogStream #42

pcreyght opened this issue Mar 13, 2018 · 5 comments

Comments

@pcreyght
Copy link

pcreyght commented Mar 13, 2018

I am hosting a small logging application in an Azure web App, using the 'microsoft.aspnetcore.all' and 'serilog.aspnetcore' nuget packages

whenever I enable the UseSerilog extension method the application stops writing logs to the azure app logstream.

public class Program
    {
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.Console()
                .WriteTo.RollingFile(@"D:\home\LogFiles\Application\diagnostics-{Date}.txt")
                .CreateLogger();

                BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseSerilog() // <-- Whenever this is enabled the logstream stops outputting logfiles
                .Build();
    }

Is it possible to use Serilog along with the logstream functionality in azure?

@nblumhardt
Copy link
Member

I think you need to add shared: true to:

.WriteTo.RollingFile(@"D:\home\LogFiles\Application\diagnostics-{Date}.txt", shared: true)

@pcreyght
Copy link
Author

pcreyght commented Mar 14, 2018

thanks for the hint:
I tried to write manually to the azure logfile folder using the rollingfile sink. This 'should' enable the stream since that folder is watched by azure, but unfortunately does not work, setting shared: true doesnt solve this for me.
According to the docs, the ASP.NET Core 2.0 automatically adds AddAzureWebAppDiagnostics() to the loggerfactory, my guess is that the UseSerilog() extension removes this feature?

@skomis-mm
Copy link

skomis-mm commented Mar 14, 2018

@pcreyght yes, this package replaces logger factory and you can see this if you enable SelfLog. If you want to preserve non-Serilog providers you need to install Serilog.Extensions.Logging separately and add Serilog via ILoggingBuilder.AddSerilog()
https://github.com/serilog/serilog-extensions-logging

@pcreyght
Copy link
Author

pcreyght commented Mar 14, 2018

@skomis-mm

add Serilog via ILoggingBuilder.AddSerilog()

That would mean going back in time! ;-) . plus I believe ASP.NET Core 2.0 is not working correctly with the ILoggingBuilder.AddSerilog() method, not reporting debug and trace logmessages.
Anyway I seem to be able to work around the issue using the FlushToDisk interval setting of the RollingFileSink like this:

.WriteTo.RollingFile(@"D:\home\LogFiles\Application\diagnostics-{Date}.txt", shared: true, flushToDiskInterval: TimeSpan.FromSeconds(5) )

This way the stream is working again!

Since the obvious end solution seems to be creating a seperate sink for this specific purpose, and as I understand correctly the issue ( UseSerilog() disables logging to Azure Diagnostics LogStream), is by design, I will close this issue.
Thank you all for pointing me in the right direction.

@nblumhardt
Copy link
Member

Thanks for the investigation and fix, Paul! I'll list this in the README 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants