Log4net when to register?

Does anyone have good information about when to register, I was thinking about registering like INFO, when I enter each C # method and write other information on exit.

Is this considered good or bad? Will performance decrease?

If I write INFO when I enter the method, the idea would be to write the method name, and the whole variable and values

Any idea how this can be done automatically without entering every value and method name, I suppose I could use reflection, but maybe I would see a slowdown here?

If reflection slows down, maybe I can just use the "REFLECTION" bit when the program is FAILS, therefore, I can write stacktrace, all the vars and values.

Any ideas or examples on this are really appreciated.

thanks

+3
source share
3 answers

You can use the AOP (Aspect oriented Programming) logging style for logging for method level logging.

There is a good structure called Log4PostSharp . This is a plugin for PostSharp that writes to Log4Net

It basically boils down to beautifying your method with this attribute:

[Log(LogLevel.Info, "Doing something")]
public void CountCharacters() {
   // do your logic here
}
+6
source

- TRACE ( log4net). DEBUG -, TRACE , . INFO, .

+2

DEBUG, INFO, INFO , . .

. , - .

, . , . .

, , .

PropertyChanged. ( )

    public string Name
    {
        get { return _Name ?? string.Empty; }
        set
        {
            _Name = value;
            NotifyPropertyChange(MethodBase.GetCurrentMethod());
        }
    }

    private void NotifyPropertyChange(MemberInfo info)
    {
        NotifyPropertyChange(info.Name.Replace("set_", string.Empty));
    }

    private void NotifyPropertyChange(string property)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(property));
    }
+1
source

Source: https://habr.com/ru/post/1708095/


All Articles