• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 46
  • Last Modified:

How will I add logging to every procedure in C# or VB.Net?

We just upgraded an application using the vb.net upgrade tool. I want to add a common procedure to all these procedures (Visual studio 2005, C# or VB.Net), Example I want to add logging and I would add "MyLogger.LogThisProcedure()" to every procedure. But it will take time for me to add this in every procedure I want to log because it was so big. Is there an add-in I can easily use to automate this, and how do I use this add-in?

Thanks.
0
stylelyf
Asked:
stylelyf
  • 2
1 Solution
 
Ronak PatelCommented:
Hi,

There is nice tool available to use for .Net Application Event Logging.

Please refer below :
A Brief Introduction to the log4net logging library, using C#
log4net Tutorial


Regards,
Ronak
0
 
stylelyfAuthor Commented:
Thanks. I plan to use this. But is there a way to automate the insertion of these class call to every procedure in my project classes?

Like

logger.Debug("Here is a debug log.");
logger.Info("... and an Info log.");
logger.Warn("... and a warning.");
logger.Error("... and an error.");
logger.Fatal("... and a fatal error.");

Open in new window


... then some kind of automatic insertion tool to insert above logger calls to my thousand procedures?
0
 
Éric MoreauSenior .Net ConsultantCommented:
It is a good time for you to discover AOP (Aspect oriented programming) available in .Net by using some tools. Have a look at https://www.postsharp.net/diagnostics/net-logging
0
 
Ronak PatelCommented:
Hi,

Here is another Logging framework which would minimize your coding efforts, but you have to apply the logger on every method you want to log.

See the demo here: Log4PostSharp - AOP and logging


Hope this helps.

Regards,
Ronak
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now