Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to log a .NET Func<>

I have a generic method that accepts a Func<int> and I would like to log the Func that is passed into the method. What properties are available on the passed in func to help me understand what it is doing?

like image 723
detroitpro Avatar asked Feb 11 '11 20:02

detroitpro


People also ask

Which .NET function would you use to get a logger?

log4net is one of the most common external logging services available to . NET developers. The developers for log4net promise you can have logging integrated with your application within minutes, and it's true—setup is easy. log4net is available in NuGet, so it's just as easy to install as it is to code.

What is .NET logging?

Logging is the process of recording events in software as they happen in real-time, along with other information such as the infrastructure details, time taken to execute, etc. Logging is an essential part of any software application.


1 Answers

You can log the method name with func.Method.Name, and there's some other useful properties in the MethodInfo class. However, if the Func is anonymous, then you will not get a very helpful name.

like image 68
wsanville Avatar answered Oct 04 '22 18:10

wsanville