The increasing complexity of Cyber-Physical Systems (CPS) increases the difficulty for users to understand their behavior. Using existing Explainable Artificial Intelligence (XAI) methods, CPS can explain their behavior to the users. However, the input-output correlations used in XAI methods are not capable of explaining certain anomalies in CPS behavior caused by contextual influences (CIs) since they do not consider the context of the CPS. Some well-known techniques used for understanding such CIs on CPS are test chambers and the analysis of logged CPS data. However, test chambers are typically only available to the manufacturer of a CPS, thus not useful for understanding CIs on the shop floors. Data analysis methods focus on data correlations, which are insufficient to explain causal relationships without using expert (human) knowledge. Hence, we propose a context-aware log-based explanation system to explain the causal relationship between CIs and the behavior of a CPS. The proposed solution employs semantic technologies to access the context of the CPS. It demonstrates the causal relationship between the CPS and CIs through counterfactual explanation and abductive reasoning methods. The contextual explanations offered by the proposed system will assist users in visualizing diverse scenarios in order to improve the CPS’ behavior accordingly.