Olivier Muhring

Olivier Muhring

  • 1.5k
  • 262
  • 9.2k

Trace logging with nLog (or similar) - how to deal with null

May 3 2018 5:12 AM
I recently started on a contract role.
 
The idea is to take full ownership of a bunch of  applications. Since there is virtually no technical documentation I've been going through the code, and adding trace logging (with NLog) where it seems appropriate.
 
A lot of the code however consists of the execution of stored procs and simply passing through dataset objects, like this:
  1. Factory.GetArchiveDataAccess().NothandledUpdate(AppSetting.StatusArchive.StatusNotHandled.GetHashCode(), Machine.DecConfigId);  
  2.   
  3. NewArchives.NewArchivesDataSet = Factory.GetArchiveDataAccess().NewArchives().ResultSet;  
  4.   
  5.  //  Trace  
  6.  if (NewArchives.NewArchivesDataSet != null && NewArchives.NewArchivesDataSet.Tables.Count > 0)  
  7.  {
  8.    _logger.Trace($"Returns {NewArchives.NewArchivesDataSet.Tables[0].Rows.Count}");  
  9. }  
  10. else  
  11. {  
  12.    _logger.Trace("NewArchives.NewArchivesDataSet does not contain data");  

 At the moment, when I want to show if a strored proc found data or not I'm forced to add a bunch of tests to avoid exceptions.
 
Isn't there a cleaner way of achieving this?
 

Answers (2)