Yes...
It would make absolutely sense for a caster to be aware when they lose concentration on a spell of their own.
"This guard hit me pretty hard, I can sense that Invisibility I gave to Tim in order to secretly enter the King's palace wore off! He must be in trouble now!"
However
The situation you describe is not the loss of concentration.
if the character attacks and the spell ends is the wizard aware ...
It's the very subject of the spell breaking it out of their own volition, something completely unrelated to the caster. Concentration is a different mechanism and, in this case, not the only one that can cause a spell to end sooner than its duration.
Ultimately, there are no rules specifying this so it's up to the DM to decide whether all casters in his world have a kind of "arcane sense" that allowed them to know exactly which of their spells are still operational and which aren't.
However, do keep in mind that accepting the above ruling can lead to some unexpected and possibly unwelcome situations. For instance, a mage casting a high duration spell, which ends on a trigger like Magic Mouth, in his sanctum/laboratory/tower/house so as to know exactly when someone entered it (triggering its ending).