Visual Studio 2017 15.4 のアップデート後、Azure Storage Emulator が起動できないときのメモ
Visual Studio 2017 15.4 のアップデート後、次のようなエラーメッセージが表示され、Azure Storage Emulator のインストールに失敗しました。
このとき、「人気のソリューションを確認する」や「問題の表示」などから、詳細のログを確認できます。
一度、Azure Storage Emulator をアンインストールし、https://docs.microsoft.com/ja-jp/azure/storage/common/storage-use-emulator#start-and-initialize-the-storage-emulator Azure ストレージ エミュレーターを使用した開発とテスト | Microsoft Docs ここから再インストールしようとしましたが、そのときもエラーが発生し、インストールができませんでした。「C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator」の中身は空っぽで、フォルダ自体も削除できない状態でした。どこのプロセスから利用しているのか見つけられなかったので、一度マシンを再起動した後、Azure Storage Emulator のみ再インストールすることで復帰しました。
下記の@takekazuomiさんの情報もご参考ください。
Storageエミュレータで使っている、sqllocaldb がオカシクなることがあるようです。 https://t.co/4lmku61vbE
— Takekazu Omi (@takekazuomi) 2017年10月16日
インストールさえ出来れば、AzureStorageEmulator.exe init /forceCreate で再作成できます
Azure Functions (C#) でのログ Tips メモ
Azure Functions (C#) でのログ Tips で、調べたことをメモしておく。 考慮漏れとして、ホスティングプランの違いにより、記載内容の挙動に違いがあるかもしれない。
概要: Azure Functions を監視する | Microsoft Docs
デフォルトの挙動
デフォルトで用意されているログの方法では、以下の場所からログを確認できる。
- App Service の診断ログ
- Azure App Service の Web アプリの診断ログの有効化 | Microsoft Docs
- 診断ログを有効にした場合、「D:\home\LogFiles\Application\Functions\function{FunctionName} 」に .log ファイルが作成される。
- Application Insights
- Azure Functions now has direct integration with Application Insights | Azure App Service Team Blog
- Key の設定が必要。Azure Functions の作成時にオプションを有効にしていれば、デフォルトで設定されているはず。
- Azure Table Storage
- これも Application Settings に接続文字列の設定が必要だが、作成時にデフォルトで設定されているはず。
構造化ログを使う場合は、後述の ILogger(Microsoft.Extensions.Logging 名前空間) を使用することで、Application Insights 上で構造化ログとして参照することができる。クエリも可能。ただし、この ILogger を使用した場合、以下の現象を確認している(現在)。
- ログの内容が、デバッグで使用する Azure Functions CLI には出力されない ※1
- ログの内容が、Azure Portal 上ののモニターからは確認できない
- ログの内容が、Azure Table Storage に出力されない
- App Service の診断ログには出力される
ILogger の使い方: プレースホルダーと C# の文字列挿入 の違いに注意すること。次の 2 つめのドキュメントを必ず参照する。
Azure Table Storage にログを格納する場合、一回の実行で出力されたログが全て、Table Entity の 1つの Property に格納される。つまり、ログのサイズが Azure Table Storage で定義されているサイズを超える場合、すべてのログが出力されるとは限らない。Azure Table Storage の1行の Max Sizeは、1MB、1 Property の Max Size は、64KB である(以下のドキュメントによる)。
実際に64KBを超えるメッセージをログとして出力してみたのだが、Azure Table Storage には、メッセージがカットされ末尾に「…」が追加されていた。
- Understanding the Table Service Data Model | Microsoft Docs
- Azure Storage Table 設計ガイド | Microsoft Docs
以上の挙動などにより、要件に合わない場合は、他サービスのロギングを使用する必要がある。
ログの期限
- App Service の診断ログ
- App Serviceと同じように、リテンション期間や保存先を選べる
- Azure App Service の Web アプリの診断ログの有効化 | Microsoft Docs
- Azure Table Storage
- Azure Table Storageの制限による
- Application Insights
- 90日間以降も残しておきたい場合は連続エクスポートを使う Application Insights からのテレメトリの連続エクスポート | Microsoft Docs
ログの参照
例えば、実行時に割り振られるユニークId—InvocationId を参照することにより、ある Function のある 実行ログを参照する、といったことができる。
InvocationId の取得方法はこちらのサイトを参照: Azure Functions で実行時のIDを取得する | ブチザッキ 情報の取得について: Retrieving information about the currently running function · Azure/azure-webjobs-sdk-script Wiki
この InvocationId は、Application Insightsや、Table Storage の RowKey 等に格納される。
Application Insights REST API を使う
Application Insights REST API で、HTTP で ログ(traces)を取得することができる。ただし今は Public Preview である。changelog: Azure Application Insights Developers Guide
Azure Application Insights Developers Guide このサイトの「Try it now」から、ブラウザ上で API のリクエストやレスポンスを確認できる。 試すときに、Application Insights の「Application ID」「API Key」が必要である。この取得方法はこちら:Azure Application Insights Developers Guide 今だと、Azure Portal から Application Insights を開き「API Access」から確認できる。 リクエストの中に書く Query は、Log Analytics のクエリ言語である:Analytics - Azure Application Insights の強力な検索ツール | Microsoft Docs
参照サイト
- Azure Functions を監視する | Microsoft Docs
- ILogger · Azure/azure-webjobs-sdk-script Wiki
- Logging in ASP.NET Core | Microsoft Docs
- Azure Functions Logging to Application Insights | Kloud Blog
- ※1 Logging written to the ILogger does not appear in the CLI · Issue #130 · Azure/azure-functions-cli
- expose ILoggerFactoryBuilder to WebHostSettings; adding app insights http tests by brettsam · Pull Request #1831 · Azure/azure-webjobs-sdk-script
- Get the instance id of a running Azure Function with ExecutionContext | Using the ExecutionContext.InvocationId you can get the unique identifier your currently running Azure Function has been assigned. Simple, quick. Zimmergren's thoughts on tech
- Azure Functions now has direct integration with Application Insights | Azure App Service Team Blog
- Azure Functions Logging written to the ILogger doesn't appear in Azure Table Storage - Stack Overflow
TraceWriter
- Microsoft.Azure.WebJobs.Script.InterceptingTraceWriter azure-webjobs-sdk/TraceWriter.cs at master · Azure/azure-webjobs-sdk
- azure-webjobs-sdk-script/InterceptingTraceWriter.cs at 7224082bcb87a775859ac6c783b24f5e918807ff · Azure/azure-webjobs-sdk-script