May 15 2023
dotnet add package Serilog dotnet add package Serilog.Extensions.Logging dotnet add package Serilog.Sinks.Console dotnet add package Serilog.Sinks.File
using Serilog; var builder = WebApplication.CreateBuilder(args); Log.Logger = new LoggerConfiguration() .WriteTo.Console() .WriteTo.File("logs/app.txt", rollingInterval: RollingInterval.Day) .CreateLogger(); builder.Logging.AddSerilog(); var app = builder.Build(); app.Run(); Log.CloseAndFlush();
.WriteTo.Console();
.WriteTo.File("logs/app.txt", rollingInterval: RollingInterval.Day);
.WriteTo.MSSqlServer("Data Source=localhost;Initial Catalog=Logging;Integrated Security=SSPI", new MSSqlServerSinkOptions { TableName = "Logs", SchemaName = "dbo", AutoCreateSqlTable = true })
dotnet add package Serilog.Sinks.Seq
.WriteTo.Seq("http://localhost:5341")
string firstName = "Stefan"; string lastName = "Djokic"; _logger.Information("User Name: {FirstName} {LastName}", firstName, lastName);
{ "Timestamp": "2023-05-14T18:32:00.1234567Z", "Level": "Information", "MessageTemplate": "User Name: {FirstName} {LastName}", "Properties": { "FirstName": "Stefan", "LastName": "Djokic" } }
[HttpGet(Name = "GetWeatherForecast")] public IEnumerable<WeatherForecast> Get() { _logger.LogInformation("Logging from {Controller}/{Action}.", typeof(WeatherForecastController).Name, nameof(Get)); _logger.LogError(new Exception("Some Exception message"), "Exception"); return GenerateRandomWeatherValues(); }
1. Design Patterns that Deliver
This isn’t just another design patterns book. Dive into real-world examples and practical solutions to real problems in real applications.Check out it here.
Go-to resource for understanding the core concepts of design patterns without the overwhelming complexity. In this concise and affordable ebook, I've distilled the essence of design patterns into an easy-to-digest format. It is a Beginner level. Check out it here.
Every Monday morning, I share 1 actionable tip on C#, .NET & Arcitecture topic, that you can use right away.
Join 18,000+ subscribers to improve your .NET Knowledge.
Subscribe to the TheCodeMan.net and be among the 18,000+ subscribers gaining practical tips and resources to enhance your .NET expertise.