The log4net Tutorial: Logging in C# (hands-on from beginner to advanced)

preview_player
Показать описание

This video will teach you how to use log4net without fear. Instead of copying and pasting confusing config files that cause more problems than they solve, watch this video and you will understand how to make log4net do exactly what you want.

You will be taken through step-by-step through the following sections:

1. Getting Started - installing log4net, initial configuration and getting it running in your code.
2. .NET 4.5 Changes - What additional options you have if you are using .NET 4.5.
3. Appenders - How to log to different data repositories like SQL Server, text files and more.
4. Filters - How to log only the data you want to capture while ignoring the rest. This will cover both the simple options as well as the more advanced possibilities.
5. Log Patterns - Learn how to capture a number of different pieces of data, what the pitfalls are of some data points and how to send data to your data source.
6. Advanced Logging - Take logging to the next level by capturing custom data in your own fields. Even capture data at the time of the error without any extra configuration.
7. Wrap Up - Review what has been learned and identify how to move forward with log4net.

This video course is easy for a beginner to get started with but even if you didn't know anything coming in, if you follow the steps outlined in the video, you will become an advanced log4net user by the end of the video. The entire video is a hands-on demonstration of not just what to do but how to do it. You will be able to follow along with the video with ease. Also provided is a link to the source code for this video. The source code has been tagged at the end of each section to indicate where you can revert to in order to see the code at any point in the video.

Course Resource:

Video Quick Use Guide:
0:00 - Intro
2:53 - Getting Started: Creating console application
4:39 - Adding NuGet reference
5:25 - Configuration
18:54 - Assembly reference
20:48 - Creating log reference (instance) for each class or entire application
25:13 - Quick recap
25:27 - Log messages
27:10 - Note on System.Reflection
27:45 - Creating LogHelper
32:40 - Appenders: File Appender - write logs in text file
37:27 - Appenders: Rolling File Appender - control log text file file size and log file quantity
44:01 - Appenders: Ado .Net Appender
54:50 - Appenders: Other Appenders
58:32 - Filters: Log message Levels
1:04:46 - Filters: Level Range filter
1:07:33 - Filters: String Match filter, filter message fall through, filter order
1:10:40 - Filters: Level Match filter
1:12:26 - Conversion pattern
1:14:15 - Conversion pattern: Log Message info
1:20:29 - Log Message length
1:23:51 - Log Message :Custom info
1:29:14 - Log Message: Dynamic variable info
1:33:11 - Summary and concluding remarks
Рекомендации по теме
Комментарии
Автор

Great video and tutorial itself. Thanks!

For those who look for quick links:

Log4net setup
4:35 -> Step 1: Add log4net package
5:25 -> Step 2: Add log4net configuration
18:54 -> Step 3: Add log4net assembly
20:47 -> Step 4: Create log4net log reference
25:30 -> Step 5: Log messages

27:56 -> Creating LogHelper
32:37 -> Appenders
1:04:46 -> Filters
1:14:13 -> Conversion pattern

kepisty
Автор

This is one of the most thorough and well taught tutorials I have ever watched. I read the article on Code Project and struggled to implement log4net and all these advanced features. This video really filled in the cracks and was a great time saver. Thank you Tim. I will be subscribing to your other videos and articles.

chipmitchell
Автор

IF you go through with this tutorial, it takes about 2 and half hour (by stopping and continue during the video) and it totally worth it. I do appreciate that Tim, its a great tutorial. I couldn't learn more in 2 and a half hour about log4net. Cheers.

berkanbilgin
Автор

0:00 - Intro
2:53 - Getting Started: Creating console application
4:39 - Adding NuGet reference
5:25 - Configuration
18:54 - Assembly reference
20:48 - Creating log reference (instance) for each class or entire application
25:13 - Quick recap
25:27 - Log messages
27:10 - Note on System.Reflection
27:45 - Creating LogHelper
32:40 - Appenders: File Appender - write logs in text file
37:27 - Appenders: Rolling File Appender - control log text file file size and log file quantity
44:01 - Appenders: Ado .Net Appender
54:50 - Appenders: Other Appenders
58:32 - Filters: Log message Levels
1:04:46 - Filters: Level Range filter
1:07:33 - Filters: String Match filter, filter message fall through, filter order
1:10:40 - Filters: Level Match filter
1:12:26 - Conversion pattern
1:14:15 - Conversion pattern: Log Message info
1:20:29 - Log Message length
1:23:51 - Log Message :Custom info
1:29:14 - Log Message: Dynamic variable info
1:33:11 - Summary and concluding remarks

I usually don't do these for videos, that already have time codes in the video description, but I figured that this was kinda long video and the time stamps could do with an update, so there... :)

P.S.
Hello Tim. If you will consider to update the time codes in the video description, I believe that they have to be in chronological order. Meaning that they have to start from zero:zero and there cannot be any other time code before that. That is, if you care for your video timeline to be split up in chapters :)
I noticed, that if you have other time stamps before zero:zero mark, YouTube wont do that for you.
Example: Your video "Top 10 Hidden Gems in Visual Studio"

RalfsBalodis
Автор

One of the best tutorial out there on log4Net. Instead of just teaching on how to make it work by some magic configuration and code, this tutorial went into details on how things work and how to customize it to our requirements. That gives a lot of confidence and comfort in using this framework than copying the configurations from random sites.

As others mentioned, the fonts are too small and if you are watching it on smaller device (even my 13" laptop display is small), you will have hard time watching it. I had to zoom my browser to 300%, and since most of the action is in top left screen that worked, but was awkward.

cmukesh
Автор

Thanks so much Tim, six years old video already, and yet very informative with my code. I never used this Log4Net before, so I needed to get my head around it fast for use in my current role!

STUPIDYOUTUBE_HIDINGMSGS
Автор

Best log4net content available on the internet. Really good, congratulations!

cleissonvas
Автор

Timothy, you've done a great job in diving into the details of log4net.

One minor comment though, is next time make the text just a bit bigger.

ecoldwell
Автор

Requires a great amount of patience to explain in detail. Great work! and a big thank you.

anandmaran
Автор

Thanks Tim! Best video covering log4net out here.

stanik
Автор

One of the best tutorials in all of YouTube. Does not matter the topic, this is

zithfrg
Автор

Bro this is seriously a 200 bucks worth tutorial. Thanks so much for giving it for free. People like you make newbies in the IT community grow and thrive.

DynamoTk
Автор

Excellent tutorial by Tim: addressing that critical point where the rubber, actually, hits the road ― ie where an end-Developer is indeed getting hands-on with an SDK..and has the VS IDE open in front of him/her to do some coding.

edwardarundcosta
Автор

This is a very good video for those who do not have knowledge on how to use Log4Net. Kudos to Timothy!!!

rajsekharbathula
Автор

killed a day on various guides, but everything was very superficial, like now we’ll make config the whole end of the guide, very cool, thanks

wadysawstiepanowicz
Автор

Thank you so much! I normally don't comment on YouTube videos, but you deserve one, especially after attentively sitting through the entire video. I'm a visual learner and what you did made all the research I did on my own click. If only you spent time on the SmtpAppender, because that alongside of the AdoNetAppender are the ones my company is using. Either way, you've gotten me 96% of the way there!! Thanks again.

Getao
Автор

Already added you in my Favorite playlist. Such an awesome video, cannot be simpler then this .
Its already over midnight and I cannot stop myself to finish the tutorial.

IchbinChandra
Автор

Again you made something that looks complicated and difficult easy to understand and use. Just what I needed for an application I am writing, great tutorial!

pickwick
Автор

great video. finished it. what I especially love is the fact that you made a branch of each section!

SaveTheHedgehog
Автор

I thought: I need now some logger. I typed: C# logging. I saw: Tim Correy log4net tutorial 1:37h. I smiled :) Thank You Tim! Thanks to that tutorial I was able to find a really annoying bug in my app.

vedymin