如何将我的Log存储到Azure表存储中我使用了语义记录

时间:2015-02-11 18:10:32

标签: azure azure-storage azure-web-roles azure-storage-blobs 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);
        }

    }
  

任何人都可以帮我保存登录Azure表存储吗?

1 个答案:

答案 0 :(得分:2)