Code optimization for event log capture