dimanche 29 mars 2015

how to log the operation of business object in an elegant way by using design pattern?

For example I have two class call Log,and Order,Order is a business object. If i need to log the insert operation of business object Order.Then i have to do something like that:



public class Order
{
IOrderDal dal = DALFactory.DataAccess.CreateOrder();
logger = new Logger();
public void Inerst(OrderInfo order)
{
dal.Insert(order);
logger.log(orderInfo.ToString(),"Insert",DateTime.Now.ToString());
}
public class Logger
{
public void log(string description,string operation,string time)
{
....//dosometing to persist the information
}
}


My question is that if i have hundreds of business object need to be logged,then i have to add the code like logger.log(orderInfo.ToString(),"Insert",DateTime.Now.ToString()) in each operation of bussiness objects?I think there must be some desgin methodlogy to make life easier.


Aucun commentaire:

Enregistrer un commentaire