Sure, as a developer you have access to the source code, but without instrumentation your applications turn into silent black boxes in production. Logging is a simple way to let your application describe its health and operations in a way that is readily consumable by both you and software, and it can provide significant insight when working out bugs. Log4net is one of the most used logging libraries for the .NET platform, with a proven track record going back to 2001. This course is aimed at getting you up and running with log4net, starting with answering the common configuration questions and moving through the entire log4net stack. Included in the course are discussions of effective and advanced logging tactics, such as applying logging through common design patterns and Aspect-Oriented programming. In addition the course demonstrates how you can tap into the modular log4net architecture and extend it with your own code.
Jim has spent over 17 years developing software for aerospace, education, and casinos. Since 2010 he has run Code Owls LLC, a company in Charlotte NC specializing in IT tooling and automation technologies. Jim is a PowerShell MVP and avid speaker.
Log Event Context This module is about Log Event Context. If you recall from our brief discussion of the log4net architecture, we use logger objects to create logging events, and these logging events are automatically associated with different aspects, such as the current thread information, and the severity level of the logging event. This module is focusing on the properties that you can associate with a logging event and the context in which those properties exist. You can use these custom properties to automatically associate any data your program has access to, to every logging event it creates. For example, let's say every time our application logs an event, we'd also like to know the current CPU utilization of the application, the number of threads the application's created, and the ambient temperature of the room in which the server lives. These custom properties will be associated with a logging event as soon as the event is created. When the logging event reaches an appender and goes through the rendering process, the appender and its associated layout can access these custom property values and use them in the rendered log.
Effective Logging This module is about using log4net effectively. The modules up to this point in the course have been focused on the guts and internals of log4net. However, this course is focused on you and your code, and how you can effectively fold log4net into your application development. The concepts in this module will revolve around three logging mantras. These are things that I constantly remind myself whenever I'm working with log4net on a day-to-day basis. We'll go into more detail on each of these mantras, and how they apply to you as we go through this module, but just to whet your appetite, here they are. First, logging code is still code. The second mantra is that logging uses resources. And the third and final mantra is log now.
Advanced Logging Tactics In this part of the course, we're going to look at Advanced Logging Tactics. These are strategies that I've learned to employ over the years to make logging a more robust and seamless experience. These tactics fall into three categories. First, we'll look at ways we can reduce the friction of working with a dated log4net API. Then we'll see how we can fold logging into. NET object patterns and design patterns. And finally, we'll see how we can apply logging with aspect-oriented programming using the PostSharp library.
Extending Log4Net In the final module for this course, we're going to look at ways that we can extend log4net. The log4net architecture allows it to be extended in five different ways. First, we'll see how we can create custom layouts, which will allow us to control log rendering in custom ways. In this module, we'll create a custom layout that formats log messages as JSON. You can also create log4net filters, which allows you to define custom filtering operations for your messages. In this module, we'll create a custom filter that can enable or disable logging for our website based on the query string. Custom appenders can be used to define proprietary ways to store your logs. For this module, we'll be creating a Custom appender that uses the Twilio API to send log messages as SMS text messages. Object renderers can be used to format specific types of objects inside of your logs. These are a lot like layouts, except instead of formatting an entire log message, object renderers are focused on specific types of objects that pass into your logs. Later in this module we'll create a custom object renderer that allows us to log the current web request in a very readable fashion. Finally, there are log4net plugins. Plugins are used to add custom initialization code when log4net is being initialized. For our demos, we'll create a custom plugin that will automatically register object renderers.