Posts

Showing posts with the label Serilog Sink

Serilog with AWS Cloudwatch on Ubuntu

Image
Serilog with AWS Cloudwatch on Ubuntu Few weeks ago we saw How to configure Serilog to work with different environment . At the end of the post, we saw briefly how to get the structured logs synced to Cloudwatch. Today we will explore the configuration in more details. Unified Cloudwatch agent Literate and json logs with Serilog Debug the Cloudwatch agent 1. Unified Cloudwatch agent The Unified Cloudwatch agent can be installed by following the official documentation https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/UseCloudWatchUnifiedAgent.html . There is a previous version of the Cloudwatch agent, this new version, introduced in December 2017, unifies the collection of metrics and logs for Cloudwatch under the same configuration. To install the agent, execute the following commands: mkdir ~/tmp cd tmp wget https://s3.amazonaws.com/amazoncloudwatch-agent/linux/amd64/latest/AmazonCloudWatchAgent.zip unzip AmazonCloudWatchAgent.zip sudo install.sh This will install ...

Multi environment logging with Serilog for AspNet Core

Multi environment logging with Serilog for AspNet Core Few months ago we saw how to get started with Serilog. We discovered what was Serilog and the different concepts of settings, enrichers and sinks. Today we will see how we can take Serilog further and configure a logging mechanism for an application running in multi environment. Setup Serilog Multi environment AWS CloudWatch 1. Setup Serilog If you have never seen Serilog before you can start with my previous post on How to get started with Serilog . In order to configure our first logging mechanism, we start by creating an AspNet Core application and install Serilog , Serilog.AspNetCore and the sinks we will be using Serilog.Sinks.Console , Serilog.Sinks.File . RollingFile sink also exists but it has been superseded with File sink. Next we can configure the logger to write to Console and write to a file: public static IWebHost BuildWebHost(string[] args) { return WebHost.CreateDefaultBuilder(args) ...

Logging in ASP NET Core with Serilog

Logging in ASP NET Core with Serilog At each stages of an application development cycle, good logs are necessary to debug and fix bugs efficiently. Serilog is a logging framework allowing developers to log structured logs into different ouput platforms. Today we will see how we can set it up in three parts Serilog for ASP.NET Core Console sink Rolling File sink Environment enricher All the code discussed here can be found on my GitHub https://github.com/Kimserey/SerilogTest . 1. Serilog for ASP.NET Core 1.1 Structured logs Logs are string messages describing an event in the system. They are built by assembling pieces of information, elapsed time or process name, into a string message. Once constructed into a message, they are written into an ouput stream, console or file for example. The message contains the timestamp the log message. The log message being a string, all we can do to query it is a full text search query. If our log contained the elapsed time, it would n...