DT Tech InfoDT Tech Info

      WPF / WPF Core

      LEARN EASY
      • Home
      • Blog
      • WPF / WPF Core
      • Logging with Serilog for WPF / WPF Core Applications

      Logging with Serilog for WPF / WPF Core Applications

      • Posted by Muthukumar Dharmar
      • Categories WPF / WPF Core
      • Date August 29, 2021

      In this short article, we will have a step by step walkthrough of implementing application logging using the Serilog library for Desktop applications with WPF / WPF Core technologies.

      About Serilog

      Serilog provides a simple and easy to use solution for application logging into files with .NET applications.  It is very easy to setup and has a clean API for logging. For more details please refer here.

      LevelUsage
      VerboseVerbose is the noisiest level, rarely (if ever) enabled for a production app.
      DebugDebug is used for internal system events that are not necessarily observable from the outside, but useful when determining how something happened.
      InformationInformation events describe things happening in the system that correspond to its responsibilities and functions. Generally these are the observable actions the system can perform.
      WarningWhen service is degraded, endangered, or may be behaving outside of its expected parameters, Warning level events are used.
      ErrorWhen functionality is unavailable or expectations broken, an Error event is used.
      FatalThe most critical level, Fatal events demand immediate attention.

      Step 1 - NuGet packages

      Install the below NuGet packages into your WPF application.

      Step 2 - Add logger file configuration into App.config

      Include the Serilog logger file configurations like file path, rolling interval, log level, etc., into the AppSettings section of the App.config file.

      Step 3 - Setup Serilog instance in Application Startup

      We can initialize our Serilog instance by invoking the below method in the OnStartup method of App.xaml.cs file. Which will set up our logger configuration based on our AppSettings.

      Step 4 - Log the events

      Now we are all setup and ready to write logs events.

      Sample log output

       

       

      Hope you have enjoyed this article 🙂

      Tag:.NET, Application Logging, C#.NET, Error Logging, Logger, WPF, WPF Core

      • Share:
      author avatar
      Muthukumar Dharmar
      Over 17 yrs of experience in the IT industry. Skill Set: Angular, RxJS Reactive Programming, AspNet WebApi, WCF, WPF, Azure, etc.,

      Previous post

      Angular - Display image from an API response
      August 29, 2021

      Next post

      Asp.Net: Reusable static assets from Razor Class Library
      April 21, 2023

      Leave A Reply Cancel reply

      Your email address will not be published. Required fields are marked *

      Search

      Categories

      • Angular
      • Angular PWA
      • ArchiMate
      • AspNet Core – Razor
      • AspNet Core – WebApi
      • Best Practices
      • Design Patterns
      • EF Core
      • Entity Framework
      • IdentityServer4
      • RxJs for Beginners
      • Tips & Tricks
      • Uncategorized
      • Web Development
      • WPF / WPF Core

      Latest Posts

      Azure: Storage Services
      26Sep2024
      Angular Styles – Tips and Tricks
      23Dec2023
      Typescript – Tips and Tricks
      23Dec2023
      logo-eduma-the-best-lms-wordpress-theme

      webadmin@dt-tech.info

      Organization

      • Contact Us

      Links

      • Blogs
      • Gallery

      Recommend

      • Angular
      • RxJS
      • AspNet Core – Razor
      • AspNet Core – WebApi
      • AspNetCore

      Powered by DT Tech.