Context conflict is a key problem since it often occurs in context-aware system when multiple users share the same context at the same time. Context conflict not only causes confusion in applications but also slows down efficiency of context-aware systems. To address these problems, we design a harmonious context-aware middleware (HCAM) and propose a logic-based approach for context conflict detection. Our contextaware middleware provides mechanisms that belong to the middleware layer to simplify development of applications. In our logic-based approach, based on rules representation, we give a classification of context conflict so that we can calculate basic context conflict information from the view of semantics of rules as well as from the view of business logic. Using the inferring axioms, we combine two views together and detect complete context conflict. Experiments show that our logic-based conflict detection approach avoids confusion in applications and reduces unnecessary execution of activated rules to improve efficiency of context-aware middleware.