Closed omidkrad closed 3 years ago
Hi! Calling AddSeq()
on the logging builder using this pattern should work:
Hope this helps!
Yes it worked, thanks. For some reason I also needed to add Microsoft.Extensions.Logging.Console
package for LoggerFactory.Create
method to work even if I don't add console logger.
That's great - thanks for the follow-up 👍
FYI for anyone else having problems using a generic host in a console app, it's critical to using
the host:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using var host = Host.CreateDefaultBuilder()
.ConfigureLogging(builder => builder
.AddConsole()
.AddSeq())
.Build();
await host.StartAsync();
var logger = host.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Hello, {Name}!", Environment.UserName);
My only change to the console example (many thanks datalust team for the example project!) is adding a dependency on the generic host packge:
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
The using
flushes any queued up log messages to Seq.
Hi, the documentations shows how to set this up on a web app using special hooks provided by ASP.NET, but how can I set it up on a simple console app?
Thanks!