0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C#でローカル コンピューターのホスト名を取得する

Posted at

1. はじめに

  • データベースやログに共通的に出力するため、実行環境のホスト名を取得したい

2. 開発環境

  • C#
  • .NET 6
  • Visual Studio 2022
  • Windows 11

3. ソースコード

public void DisplayLocalHostName()
{
   try {
      // ローカル コンピューターのホスト名を取得
      String hostName = Dns.GetHostName();
      Console.WriteLine("Computer name :" + hostName);
   }
   catch(Exception e)
   {
       // TODO: エラー処理
       Console.WriteLine("Exception caught!!!");
       Console.WriteLine("Source : " + e.Source);
       Console.WriteLine("Message : " + e.Message);
   }

4. 参考文献

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?