You can use error logging mechanism, like log4net framework etc..