title: Conditional Definition with Using in VB.net
body: <p>I want to avoid duplicating code to write to a log file conditionally, as I'm doing below. Is there a better solution in VB.net?</p>
  
  <pre><code>If Not System.IO.File.Exists(log_file_address) Then
      Using log_file_stream as New System.IO.StreamWriter(log_file_address)
          log_file_stream.Writeline (current_time_string)
          log_file_stream.Writeline (" ")
          log_file_stream.Writeline (log_message)
          log_file_stream.Close()
      End Using
  Else
      Using log_file_stream As IO.StreamWriter = System.IO.File.AppendText(log_file_address)
          log_file_stream.Writeline (current_time_string)
          log_file_stream.Writeline (" ")
          log_file_stream.Writeline (log_message)
          log_file_stream.Close()
      End Using
  End If
  </code></pre>
  
  <p>Perhaps something like:</p>
  
  <pre><code>Using log_file_stream as If(System.IO.File.Exists(log_file_address), _
                              System.IO.File.AppendText(log_file_address), _
                              New System.IO.StreamWriter(log_file_address))
      log_file_stream.Writeline (current_time_string)
      log_file_stream.Writeline (" ")
      log_file_stream.Writeline (log_message)
      log_file_stream.Close()
  End Using
  </code></pre>