私は現在、WebApiとSQL Serverを使って新しいプロジェクトに取り組んでいますが、ログを生成して保存する必要があるすべてのアプリケーションで、問題を作成する方法と、私はAzureを使用しているのでAzure Blob Tableがあります。これはログを作成するのには完璧ですが、私は専門家ではありません。だから、ログされているすべてのユーザーは、どのようにこれを整理するために、私はいくつかの助けが必要です!AzureでWebApiを使ってログを作成する
0
A
答えて
1
Azure Web Appは、アプリケーションログ機能を提供し、Azureポータルで有効にすることができます。その後
、我々は次のコードとログを使用してログイン書くことができ、私はAzureのポータル上で設定されたブロブに書き込まれます。
Trace.TraceInformation("Hello Azure Log");
アプリケーションログをAzureテーブルストレージに書き込む場合は、カスタムTraceListenerを作成できます。 AzureTableStorageListenerを作成しました。AzureTableStorageListenerはトレースログをAzure Tableに書き込みます。下のコードは参照用です。
public class AzureTableStorageTraceListener : System.Diagnostics.TraceListener
{
protected override string[] GetSupportedAttributes()
{
return new[] { "StorageConnectionString", "LogsTableName" };
}
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
{
Write(message, eventType.ToString());
}
public override void Write(string message, string category)
{
string stroageConnectionString = Attributes["StorageConnectionString"];
string tableName = Attributes["LogsTableName"];
// Retrieve the storage account from the connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(stroageConnectionString);
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "people" table.
CloudTable table = tableClient.GetTableReference(tableName);
// Create a new log entity.
LogEntity log = new LogEntity(category, message);
// Create the TableOperation object that inserts the log entity.
TableOperation insertOperation = TableOperation.Insert(log);
// Execute the insert operation.
table.Execute(insertOperation);
}
public override void WriteLine(string message, string category)
{
Write(message + "\n", category);
}
public override void Write(string message)
{
Write(message, null);
}
public override void WriteLine(string message)
{
Write(message + "\n");
}
}
public class LogEntity : TableEntity
{
public LogEntity(string category, string message)
{
category = category == null ? "Default" : category;
this.PartitionKey = category;
this.RowKey = Guid.NewGuid().ToString();
this.Message = message;
this.CreatedDate = DateTime.Now;
}
public LogEntity() { }
public string Category { get; set; }
public string Message { get; set; }
public DateTime CreatedDate { get; set; }
}
このTraceListenerを使用するには、次の構成セクションをWeb.configに追加する必要があります。
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="AzureTableStorageListener"
type="{your namespace name}.AzureTableStorageTraceListener,{your assembly name which contains the custom trace listener}"
StorageConnectionString="{your storage connection string}"
LogsTableName="{azure storage table name}"/>
</listeners>
</trace>
</system.diagnostics>
+0
ありがとうございました! :D –
関連する問題
- 1. azureでpythonを使ってdocumentdbアカウントを作成するには?
- 2. AzureでBitnami Solrを使ってコアディレクトリを作成する
- 3. vbaを使ってパワーポイント2007のログを作成するには?
- 4. Powershellを使ってAzure Flaskを作成する
- 5. Azure ADとAzure B2Bを使用する認証WebAPIサービス
- 6. log4j2を使って半日ログを生成する方法は?
- 7. awkを使ってapache httpログからレポートを生成する
- 8. IISログのWebAPIルート
- 9. WebApiでEntity Frameworkとコードファーストを使用してデータベースを作成する方法
- 10. io.Multiwriterを使用してパッケージ/サブパッケージ間にログを作成する
- 11. Javaを使用してMySQLログを作成する方法
- 12. WebAPIコールからJSONを使用してAndroidフォームを作成
- 13. PowerShellでログを作成する
- 14. azure asp.net core webapi-onlyアプリを
- 15. MVC4/WebAPIでRSSフィードを作成
- 16. セレンを使ってPythonで生成されたログを保存するには
- 17. Pythonでログ・ログ・ヒストグラムを作成する方法
- 18. WebApiカスタムログとAzureストレージ
- 19. AzureサービスファブリックWebAPI with SignalR
- 20. Host WebAPI to Azure Error:HelpPage_Default
- 21. Microsoft Asp.net WebApiを使用して依存性注入を作成する方法
- 22. Python SDKを使用してAzureアプリケーションゲートウェイを作成する方法
- 23. C#を使用してAzure Webアプリケーションを作成する
- 24. DevTestLabsのPython Azure SDKを使用してカスタムイメージを作成する
- 25. REST APIを使用してazureストレージにディレクトリを作成する
- 26. Azureナビゲーションポータルを作成する
- 27. AzureでiTextSharpでPDFを作成する
- 28. Azure Storage Emulatorを使って作業すると、404
- 29. Azure(nodejs)のhttptriggerを使ったボットサービスの作成
- 30. webapiからaxios.postを使ってファイルをダウンロードするには
私はアプリケーションの洞察力と同じように晴れやかな方法で行くだろう –