How to do it...

  1. Create a class called Chapter3 (if you have not done so already) that contains two methods. One method reads the XML file, and the second method logs any exception errors:
        public void ReadXMLFile(string fileName)        {          try          {            bool blnReadFileFlag = true;            if (blnReadFileFlag)            {              File.ReadAllLines(fileName);            }          }          catch (Exception ex)          {            Log(ex);            throw;          }        }        private void Log(Exception e)        {          /* Log the error */        }
  1. In the console application, add the following code to call the ReadXMLFile method, passing it the filename to read:
Chapter3 ch3 = new Chapter3();string File = @"c:tempXmlFile.xml";ch3.ReadXMLFile(File);
  1. Running the application will generate an error (assuming that you actually don't have a file called XMLFile.xml in your ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.