ASP.NET Core include timestamp in all log entries
As indicated in the linked question, this feature is now built-in to the Microsoft.Extensions.Logging.Console. You can activate it by setting the TimestampFormat:
new ServiceCollection()
.AddLogging(opt =>
{
opt.AddConsole(c =>
{
c.TimestampFormat = "[HH:mm:ss] ";
});
})
Using a third-party solution is the right answer.
As explained in the same github discussion you linked about the built-in logging:
This really is a logging abstraction, the default sinks are very extremely basic and usually farm out to other systems to get more features.
and
There are so many amazing 3rd party logging systems with richer features than what we will ever provide OOTB. I'd recommend you use those in your production applications.
I would strongly recommend (also in the github issue) that you consider a well-maintained structured-logging package like Serilog.
I'm sure the custom code you linked is probably fine, but Serilog has many contributors and you can be sure it'll be up-to-date well into the future. The main page will link you to extensions specific to ASP.NET Core logging. (I don't have any vested interest in the product, but I do use it, it's quite easy to set up and use, and is very flexible.)
Structured logging lets you add arbitrary JSON data to your logs, which is a huge benefit during troubleshooting over simple "write a string of text" logging like we used to do.