简体   繁体   English

语义应用程序日志记录块 - 在asp.net应用程序中登录控制台

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

I am using Semantic Logging Application Block in our asp.net c# application. 我在asp.net c#应用程序中使用语义记录应用程序块 I am developing using Visual Studio 2013. I have created a listener which logs to a flat file and this works fine. 我正在使用Visual Studio 2013开发。我创建了一个监听器,它记录到一个平面文件,这很好。

But I cannot get Console.LogToConsole to work. 但是我无法让Console.LogToConsole工作。 ie, I don't see the log message in the Visual Studio Output window. 即,我没有在Visual Studio输出窗口中看到日志消息。 I have checked the Immediate window and the log messages are not visible there either. 我已经检查了立即窗口,并且在那里也看不到日志消息。 Any suggestions are much appreciated. 任何建议都非常感谢。

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: 派对迟到但您可以创建一个自定义事件监听器,它可以写入您喜欢的任何内容(在本例中为Debug),如下所示:

    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 感谢: http//www.shujaat.net/2013/08/slab-reactive-event-sourcing.html

I ran into the same thing as I first started with visual studio. 我遇到了与Visual Studio最初开始时相同的事情。 Console.LogToConsole does what it says, logs to the console in a console app. Console.LogToConsole执行它所说的内容,在控制台应用程序中记录到控制台。 Neither the Output nor Immediate windows are the console. 输出和立即窗口都不是控制台。 The console looks like a DOS window. 控制台看起来像DOS窗口。 You wouldn't see this running an ASP.Net site. 你不会看到这运行ASP.Net站点。 You would have to specifically create a console application. 您必须专门创建一个控制台应用程序。 One note to mention, if you're debugging or running a console app within visual studio, sometimes the console window would be behind visual studio. 需要注意的一点是,如果您在visual studio中调试或运行控制台应用程序,有时控制台窗口将落后于visual studio。 Look for the icon that pops up in your windows task bar. 查找Windows任务栏中弹出的图标。 Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM