I have a class that loga some information in the database I am using it as follows:
new StudyLogRepository().Create(new StudyLog() {
StudyId = Study.Id,
CycleId = null,
DateOccurrence = DateTime.Now,
CycleActionName = "Nova estudo gerado",
UserId = int.Parse(System.Web.HttpContext.Current.Session[SessionKeys.USER_ID].ToString())
});
But in the same method I end up having to log in various information, so I end up having this code duplicated in several classes and methods making maintenance super complicated.
How can I solve this problem of duplicate code where the data to be logged in always comes directly from the class or method where this duplicate excerpt exists?