In the search condition use AND instead of commas. Also it is easier to read the statements if you use @ quoted literals. So perhaps something like:
string mergeSql = @"
merge into logDetail as Target
using #templogDetail as Source
on Target.L_DateTime=Source.L_DateTime
and Target.L_Direction=Source.L_Direction
and Target.L_CardID=Source.L_CardID
when matched then
update set Target.L_GateID=Source.L_GateID
when not matched then
insert (L_DateTime,L_Direction,L_CardID,L_GateID)
values(Source.L_DateTime,Source.L_Direction,Source.L_CardID,Source.L_GateID);";