How it works...

In the first step, we opened the terminal window in the Ubuntu system. This terminal is similar to the command window you use in Windows operating systems. A terminal helps you to execute shell commands supported by the .NET Core 2.0. In step 2, we created a blank solution. The dotnet new command creates a new solution file containing directories. In step 3, we changed the directory to the root of the solution file. From this point onwards, we will be adding the projects to the solution.

In step 4, we used the same dotnet new command to create the class library. By default, this class library will use the .NET Standard 2.0 library, so we don't have to tell the command-line tool to create the .NET Standard 2.0 library. We can confirm this by expanding the Chapter3.LogFile.LogLib node in Visual Studio Code, then clicking on the Chapter3.LogFile.LogLib.csproj label. In the right-hand pane of Visual Studio Code, you will be able to see this XML code:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>

In this code, <TargetFramwork> markup says it's netstandard2.0 and it's confirmed, we have a .NET Standard 2.0 library on our hands. In steps 6 to 10, we used Visual Studio Code to open the current directory and make changes to the existing class. In step 11, we made sure we were in the root directory of the solution. In step 12, we added the Class Library project to the solution using the command-line tool. You will be able to list all the projects in the solution by executing the following command in the terminal:

$ dotnet sln list 

The command will list all the available projects in the current solution file. In step 13, we performed a build command to make sure everything was intact and working fine. In step 15, we added the namespace for handing inputs and outputs to the system. The System.IO namespace contains all the file handling classes inside it.

In step 16, we created two private variables to hold the filename and StreamWriter class that helps you to write to text files. In step 17, we created a constructor method that checks whether the file, exists. If it doesn't exist, it will create a whole new text file and, if there is a file already, we will open the file to append text to it. This is a very good practice when you handle files for these sort of tasks.

In step 18, we created a method that takes a string parameter as the message and writes that message to the file. In step 19, we created a method to close the opened file. Finally, step 20 verified that the syntax is OK and builds correctly using a build command.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.133.233