如何将我的日志存储到 Azure table 存储中 我使用了语义日志记录
How do I store my Log into Azure table storage I used Semantic Logging
对于应用程序日志记录,我使用了 Semantic Logging
,但我想将登录保存到 Azure table storage
,现在我只是在控制台上显示它。
static void Main(string[] args)
{
//create a listner and subscribe to event source
var listener1 = ConsoleLog.CreateListener();
MyEventSource Log = new MyEventSource();
listener1.EnableEvents(Log , EventLevel.Verbose);
//log
Log.ApplicationStart("Start console", "user 1");
var ordersProcessed = 0;
for (int i = 0; i < 10; i++)
{
ordersProcessed++;
Console.WriteLine("Order no {0} is processed " , ordersProcessed);
}
//log
Log.ApplicationEnd("Finished", ordersProcessed);
Console.ReadLine();
}
class MyEventSource : EventSource
{
[Event(100,Message="Application Started..")]
public void ApplicationStart(string startMessage, string userName)
{
if (this.IsEnabled()) //helps to avoid processing events that no listeners have been configure for
{
WriteEvent(100, startMessage, this.MyUtilityMethod(userName));
}
}
[Event(500, Message = "Application Ended..")]
public void ApplicationEnd(string endMessage, int ordersProcessed)
{
if (this.IsEnabled()) //helps to avoid processing events that no listeners have been configure for
{
WriteEvent(500, endMessage, ordersProcessed);
}
}
//demonstrate method which are not part of EventSource contract
private string MyUtilityMethod(string userName)
{
return string.Format("User {0} " , userName);
}
}
Can any one help me to save log into Azure table storage?
我认为此博客 post 可能会有所帮助 - https://robindotnet.wordpress.com/2014/07/19/implementing-slab-in-an-azure-service/
对于应用程序日志记录,我使用了 Semantic Logging
,但我想将登录保存到 Azure table storage
,现在我只是在控制台上显示它。
static void Main(string[] args)
{
//create a listner and subscribe to event source
var listener1 = ConsoleLog.CreateListener();
MyEventSource Log = new MyEventSource();
listener1.EnableEvents(Log , EventLevel.Verbose);
//log
Log.ApplicationStart("Start console", "user 1");
var ordersProcessed = 0;
for (int i = 0; i < 10; i++)
{
ordersProcessed++;
Console.WriteLine("Order no {0} is processed " , ordersProcessed);
}
//log
Log.ApplicationEnd("Finished", ordersProcessed);
Console.ReadLine();
}
class MyEventSource : EventSource
{
[Event(100,Message="Application Started..")]
public void ApplicationStart(string startMessage, string userName)
{
if (this.IsEnabled()) //helps to avoid processing events that no listeners have been configure for
{
WriteEvent(100, startMessage, this.MyUtilityMethod(userName));
}
}
[Event(500, Message = "Application Ended..")]
public void ApplicationEnd(string endMessage, int ordersProcessed)
{
if (this.IsEnabled()) //helps to avoid processing events that no listeners have been configure for
{
WriteEvent(500, endMessage, ordersProcessed);
}
}
//demonstrate method which are not part of EventSource contract
private string MyUtilityMethod(string userName)
{
return string.Format("User {0} " , userName);
}
}
Can any one help me to save log into Azure table storage?
我认为此博客 post 可能会有所帮助 - https://robindotnet.wordpress.com/2014/07/19/implementing-slab-in-an-azure-service/