我想拋出一些自定義異常並將其寫入日誌。
關於寫入日誌的正確位置的最佳實踐是什麼:BLL或Exception構造函數本身?將錯誤寫入日誌的最佳位置在哪裏? (BLL或ExceptionConstructor)
class TaskDataValidationFailedException : Exception
{
public TaskDataValidationFailedException(TaskValidationResult validation)
{
this.validation = validation;
//SHOULD I WRITE THE LOG HERE?
_log.Info("Task " + task.Name + " valication failed");
}
}
or here?
if (!validation.validationSucceeded)
{
throw new TaskDataValidationFailedException(validation);
//OR SHOULD I WRITE THE LOG HERE?
_log.Info("Task " + task.Name + " valication failed");
}