Electrocatalytic CO2 reduction reaction (CO2RR) emerges as a promising avenue to mitigate carbon emissions, enabling the capture and conversion of CO2 into high-value products such as syngas with CO/H2. One of the crucial aspects lies in the tailored development of durable and efficient electrocatalysts for the CO2RR. Covalent organic frameworks (COFs) possess unique characteristics that render them attractive candidates for catalytic applications. However, the relationship between structure and performance still requires further exploration; especially, most COFs with such properties are limited to COFs containing specific groups such as phthalocyanine or porphyrin groups. Here, we custom-synthesize two azine-linked nitrogen-rich COFs constructed from triazine building blocks, which are doped with ultrafine and highly dispersed Ag nanoparticles (Ag@TFPT-HZ and Ag@TPT-HZ). Thus-obtained COFs can serve as electrocatalysts for the CO2RR, and a comprehensive investigation has been conducted to uncover the intricate structure-performance relationship within these materials. Notably, Ag@TFPT-HZ exhibits superior CO selectivity in the electrocatalytic CO2RR, achieving a FECO of 81% and a partial current density of 7.65 mA·cm-2 at the potential of -1.0 V (vs reversible hydrogen electrode (RHE)). In addition, Ag@TPT-HZ as an electrocatalyst can continuously produce syngas with a CO/H2 molar ratio of 1:1, an ideal condition for methanol synthesis. The observed distinct performance between these two COFs is attributed to the presence of O atoms in TFPT-HZ. These O atoms facilitate a higher loading capacity of Ag nanoparticles (11 wt %) and generate a greater number of active sites, thereby enhancing electrochemical activity and promoting faster reaction kinetics. Therefore, two tailor-made two-dimensional (2D) nitrogen-rich COFs with various active sites as electrocatalysts can exhibit different outstanding electrocatalytic performances for CO2RR and possess high cycling stability (>50 h). This work offers valuable insights into the design and synthesis of electrocatalysts, particularly in elucidating the intricate relationship between their structure and performance.