PostSharp有一项功能,只需使用方法上的属性即可在输入和退出方法时进行记录。我想模仿同样的想法,但我不确定他们是如何实现这一目标的。
[Log]
public void Save(string firstName, string lastName, string streetAddress, string city)
{
var customerRepository = new CustomerRepository();
customerRepository.Save(firstName, lastName, streetAddress, city);
}
为了做到这一点,我需要构建什么?
答案 0 :(得分:0)
我不确定C#
中是否存在任何此类内置功能,但为什么您只能在控制台/文件中打印一行,如下所示
public void Save(string firstName, string lastName, string streetAddress, string city)
{
Console.WriteLine("Method Entered @ {0}", DateTime.Now.ToString());
var customerRepository = new CustomerRepository();
customerRepository.Save(firstName, lastName, streetAddress, city);
Console.WriteLine("Method Exited @ {0}", DateTime.Now.ToString());
}