1

对于我使用过的应用程序日志记录,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 表存储中?

4

1 回答 1

2

我认为这篇博文可能会有所帮助 - https://robindotnet.wordpress.com/2014/07/19/implementing-slab-in-an-azure-service/

于 2015-02-11T18:42:30.527 回答