Handle 404 using web.config custom errors, this is the correct way to handle this type of errors, and in NotFound.aspx page you can log the error.
<configuration>
<system.web>
<customErrors mode="On" >
<error statusCode="404" redirect="NotFound.aspx"/>
</customErrors>
</system.web>
</configuration
Noway to handle all 404 exceptions from code behind, because the generic handler of exception could be implemented in global.asax - (Application_Error method), this handler able to catch any error occurred on asp.net application layer and cannot handle 404 request because you are request something outside of asp.net.