Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic Application Logging Block - Console logging in asp.net application

I am using Semantic Logging Application Block in our asp.net c# application. I am developing using Visual Studio 2013. I have created a listener which logs to a flat file and this works fine.

But I cannot get Console.LogToConsole to work. i.e., I don't see the log message in the Visual Studio Output window. I have checked the Immediate window and the log messages are not visible there either. Any suggestions are much appreciated.

like image 692
Jerome Anthony Avatar asked Dec 06 '25 10:12

Jerome Anthony


1 Answers

Bit late to the party but you can create a custom event listener that writes to whatever you prefer (in this case Debug) like so:

    internal class MyEventListener : EventListener
    {
        protected override void OnEventSourceCreated(EventSource eventSource)
        {
            base.OnEventSourceCreated(eventSource);

            Debug.WriteLine("Listener attached to the source");
        }

        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            ICollection readOnlyCollectionObject = (ICollection)eventData.Payload;
            object[] payload = new ArrayList(readOnlyCollectionObject).ToArray();

            Debug.WriteLine(eventData.Message, payload);
        }
    }

And then, with our custom event listener built, we simply fire it up in the normal fashion:

var listener = new MyEventListener();
listener.EnableEvents(MyEventSource.Log, EventLevel.Informational);

MyEventSource.Log.MyEvent("Hello from the Immediate window!");

Credit to: http://www.shujaat.net/2013/08/slab-reactive-event-sourcing.html

like image 90
user1393477 Avatar answered Dec 08 '25 02:12

user1393477



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!