0

The question is actually this; I need info message for every method's start and end. For example I have a code block:

    public void MethodName(ObjectName object)
        {
            try
            {
             LOG.Info(MethodBase.GetCurrentMethod());

              // Some codes in here
            }
            catch (Exception e)
            {
                LOG.Error(e.Message);
            }
        }

I don't want to write Log.Info for every method. Any suggestion ?

Berkay Kirmizioglu
  • 1,134
  • 1
  • 11
  • 23
  • By the way, I deleted real code block and object names for security issues. Sorry for that – Berkay Kirmizioglu May 23 '17 at 07:25
  • https://stackoverflow.com/questions/38325824/log-method-entry-and-exit-in-net-using-nlog – CodeCaster May 23 '17 at 07:32
  • I believe you can find some useful information in this question: https://stackoverflow.com/questions/171285/logging-entry-and-exit-of-methods-along-with-parameters-automagically – sasha_gud May 23 '17 at 07:32
  • I saw these posts but there was not an accepted answer there – Berkay Kirmizioglu May 23 '17 at 07:38
  • @CodeCaster question is not duplicate, I don't want to write any log.info, log.error etc. For example private static readonly ILog LOG = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); added beginning of the class, and just using it. I need something like that actually. You missed understand me – Berkay Kirmizioglu May 23 '17 at 07:46
  • No, you misunderstand the duplicate. The solution is Aspect-Oriented Programming where you rewrite every (or chosen) method to include a pre and post log statement. – CodeCaster May 23 '17 at 08:54
  • Okay then, I thank you for your explanations. I am trying to do https://stackoverflow.com/questions/25803/how-do-i-intercept-a-method-call-in-c – Berkay Kirmizioglu May 23 '17 at 10:30

0 Answers0