Automatic logging using C #

I have a class and I want to log every action that is performed on the class.

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
             Log.Info("button clicked");
        }
    }

      

For example: if someone creates an instance of the class, so I can write it to a file. Same thing, if any variable or function is set, I want it to be automatically registered. There are several ways to log using log4net

using a method Log.Info()

inside my class or inside each method that I want to log. For that I have to put this code all over the place. Instead, I want to dynamically record events without logging Log.Info()

everywhere.

+3


source to share





All Articles