azureazure-storageazure-web-rolesazure-blob-storagesemantic-logging

How do I store my Log into Azure table storage I used Semantic Logging


For application logging I have used Semantic Logging but I want to save logging into Azure table storage, now I just displayed it on Console.

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);
        }

    }

How can I save log into Azure table storage?


Solution

  • I think this blog post might help - https://robindotnet.wordpress.com/2014/07/19/implementing-slab-in-an-azure-service/