In this recipe, we will be looking at exception handling inside a .NET class library. We will be reusing the same library created in the first recipe of this chapter.
Make sure you have completed the two recipes from this chapter. Open the solution and perform a quick build to check that everything is fine and compiles well.
- Open Visual Studio 2017.
- Now, open the solution from the previous recipe. Click
File
|Open
|Open Project/Solution
, or press Ctrl + Shift + O, and select theChapter10.Logging
solution. - Press Ctrl + Shift + B for a quick build to check that everything is fine.
- The
Solution Explorer
should look like this:
- Now, double-click on the
LoggerDemo.cs
label to open the code window. - Scroll down until you reach the
WriteLog()
method. - Replace the current code with the following:
try { if (!File.Exists(logFileName)) { logFile = File.CreateText(logFileName...