I wrote a simple wrapper around log4net.
public class Logger { private ILog _Log { get; set; } public Logger(Type declaringType) { _Log = LogManager.GetLogger(declaringType); } public void Error(Exception exception, [CallerMemberName] string callerMemberName = "") { _Log.Error(callerMemberName, exception); } }
In the code that does the logging, simply do:
private Logger Log = new Logger(MethodBase.GetCurrentMethod().DeclaringType);
Of course, if you want to do things like Info, Debug, etc., you can just add it to the shell class.
Note
it uses C # 5.0 [CallerMemberName]
ScubaSteve May 12 '15 at 12:17 a.m. 2015-05-12 00:17
source share