Reputation: 2506
I am able to write logs to Azure table storage in my MVC app using AzureTableStorage
like this:
var storage = CloudStorageAccount
.Parse(ConfigurationManager.AppSettings["AzureStorageConnectionString"]);
string tableName = Constants.AzureLogTableName;
_log = new LoggerConfiguration()
.WriteTo.AzureTableStorageWithProperties(storage, storageTableName: tableName)
.MinimumLevel.Debug()
.CreateLogger();
_log.Error("Error");
How can I read the logs from table storage?
I have spent about 20 minutes looking at documentation on the AzureTableStorage and Serilog GitHub
projects and also searched Stack Overflow but I can't figure out how to do it.
What am I missing?
Upvotes: 2
Views: 1159
Reputation: 8491
How can I read the logs from table storage?
Logs in Azure Table are like this,
To read them out, you could use the Azure Table Storage C# SDK to read data from the log table.
public class LogEntity : TableEntity
{
public LogEntity() { }
public string MessageTemplate { get; set; }
public string Level { get; set; }
public string RenderedMessage { get; set; }
}
var storage = CloudStorageAccount
.Parse(ConfigurationManager.AppSettings["AzureStorageConnectionString"]);
CloudTableClient tableClient = storage.CreateCloudTableClient();
string tableName = Constants.AzureLogTableName;
CloudTable table = tableClient.GetTableReference(tableName);
TableQuery<LogEntity> query = new TableQuery<LogEntity>();
// Print the fields for each customer.
foreach (LogEntity entity in table.ExecuteQuery(query))
{
Console.WriteLine("{0}, {1}\t{2}\t{3}\t{4}", entity.PartitionKey, entity.RowKey,
entity.MessageTemplate, entity.Level, entity.RenderedMessage);
}
Upvotes: 3