title: Read first line of a text file c#
body: <p>I'm trying to read the MDT (Microsoft Deployment Tool) log details when it is created using Visual Studio C# and display <strong>start time and date</strong> in my ConsoleApp for my project. I'm a beginner for C# and having a hard time to code. Can someone please help me with the C# code and available libraries required for the same?</p>
  
  <p>I want to know when the process has started.</p>
  
  <p>Below is an example of the file that is created.</p>
  
  <pre class="lang-text prettyprint-override"><code>&lt;![LOG[LOGGING: Finalize process ID set to 1036]LOG]!&gt;&lt;time="09:14:26.336+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1040" file="tslogging.cpp:1864"&gt;
  &lt;![LOG[==============================[ TSBootShell.exe ]==============================]LOG]!&gt;&lt;time="09:14:26.336+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1040" file="bootshell.cpp:1206"&gt;
  &lt;![LOG[Succeeded loading resource DLL 'X:\sms\bin\x64\1033\TSRES.DLL']LOG]!&gt;&lt;time="09:14:26.336+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1040" file="util.cpp:972"&gt;
  &lt;![LOG[Debug shell is enabled]LOG]!&gt;&lt;time="09:14:26.336+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1040" file="bootshell.cpp:1217"&gt;
  &lt;![LOG[Waiting for PNP initialization...]LOG]!&gt;&lt;time="09:14:26.351+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="bootshell.cpp:69"&gt;
  &lt;![LOG[RAM Disk Boot Path: MULTI(0)DISK(0)RDISK(0)PARTITION(1)\SOURCES\BOOT.WIM]LOG]!&gt;&lt;time="09:14:26.351+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="configpath.cpp:322"&gt;
  &lt;![LOG[WinPE boot path: D:\SOURCES\BOOT.WIM]LOG]!&gt;&lt;time="09:14:26.351+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="configpath.cpp:347"&gt;
  &lt;![LOG[Booted from removable device]LOG]!&gt;&lt;time="09:14:26.351+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="configpath.cpp:377"&gt;
  &lt;![LOG[Found config path D:\]LOG]!&gt;&lt;time="09:14:26.351+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="bootshell.cpp:656"&gt;
  &lt;![LOG[Booting from removable media, not restoring bootloaders on hard drive]LOG]!&gt;&lt;time="09:14:26.351+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="bootshell.cpp:721"&gt;
  &lt;![LOG[D:\WinPE does not exist.]LOG]!&gt;&lt;time="09:14:26.523+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="bootshell.cpp:738"&gt;
  &lt;![LOG[D:\_SmsTsWinPE\WinPE does not exist.]LOG]!&gt;&lt;time="09:14:26.523+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="bootshell.cpp:752"&gt;
  &lt;![LOG[Executing command line: wpeinit.exe -winpe]LOG]!&gt;&lt;time="09:14:26.539+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="bootshell.cpp:1011"&gt;
  &lt;![LOG[The command completed successfully.]LOG]!&gt;&lt;time="09:14:32.378+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="bootshell.cpp:1093"&gt;
  &lt;![LOG[Setting offline Windows drive and OS root directory to TS envirtonment.]LOG]!&gt;&lt;time="09:14:32.378+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="bootshell.cpp:806"&gt;
  &lt;![LOG[  Processing volume D:\ ]LOG]!&gt;&lt;time="09:14:32.378+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="bootshell.cpp:549"&gt;
  &lt;![LOG[  Volume D:\ is not a local hard drive.]LOG]!&gt;&lt;time="09:14:32.378+480" date="01-16-2018" component="TSBootShell" context="" type="1" thread="1056" file="bootshell.cpp:552"&gt;
  </code></pre>
  
  <p>And this is my code:</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Text;
  
  class Test
  {
      public static void Main()
      {
          string path = @"c:\1.txt";
  
  
          // Open the file to read from.
          using (StreamReader sr = File.OpenText(path))
          {
              string s = "";
              while ((s = sr.ReadLine()) != null)
              {
                  Console.WriteLine(s);
              }
              Console.ReadLine();
          }
      }
  }
  </code></pre>
  
  <p>How can I read only the first line from a text file and extract date and time from the log file?</p>