Home

Dumping in different panel

Is there a way to use dump() in a new panel?

Comments

  • There's nothing obvious in the Dump API suggesting you can redirect it to another panel, but this query may give you alternate ideas:
    Util.SqlOutputWriter.WriteLine("Just testing...")
    Dim out2 = (New TextBox).Dump
    out2.Text = PanelManager.GetOutputPanels().Dump()(0).Heading
  • You could write an extension method in the 'My Extensions' query like this:
    public static T DumpX<T> (this T toDump, string panelName)
    {
        System.Windows.Forms.WebBrowser browser;
        TextWriter formatter;
    
        var panel = PanelManager.GetOutputPanel (panelName);
        bool first = panel == null;
        if (first)
        {
            panel = PanelManager.DisplayControl (browser = new System.Windows.Forms.WebBrowser(), panelName);
            formatter = Util.CreateXhtmlWriter (true);
            browser.Tag = formatter;
            bool init = true;
            browser.DocumentCompleted += (sender, args) =>
            {
                if (init) browser.DocumentText = formatter.ToString();
                init = false;
            };
        }
        else
        {
            browser = (System.Windows.Forms.WebBrowser)(panel.GetControl());
            formatter = (TextWriter)browser.Tag;
        }
    
        formatter.WriteLine (toDump);
    
        if (first || browser.ReadyState == System.Windows.Forms.WebBrowserReadyState.Complete)
            browser.DocumentText = formatter.ToString();
    
        return toDump;
    }
    
    This will give basic Dump functionality, although without some features such as headings, DumpContainers, observables, etc.
  • Thanks to both of you!
  • Would you please add an example for dumping an observable? I can't get it without flicker...
  • I also wrote this, which works fine in a simple example but when using it with some async code, the new panel doesn't even appear :(

    [NLog.Targets.Target("LinqPadPanelTarget")] class LinqPadPanelTarget : NLog.Targets.TargetWithLayout { public string PanelName { get; set; } = "Logging"; protected override void Write(NLog.LogEventInfo log) { string line = Layout.Render(log); line.DumpToPanel(PanelName); } }

    static void RedirectNLogToLoggingPanel(NLog.LogLevel minLevel = null, string panelName = null) { var config = NLog.LogManager.Configuration; if (config == null) config = NLog.LogManager.Configuration = new NLog.Config.LoggingConfiguration(); var target = new LinqPadPanelTarget(); if(panelName != null) target.PanelName = panelName; NLog.LogManager.Configuration.AddTarget("linqpad", target); NLog.LogManager.Configuration.AddRule(minLevel ?? NLog.LogLevel.Trace, NLog.LogLevel.Fatal, "linqpad"); NLog.LogManager.ReconfigExistingLoggers(); }
  • Repro:

    RedirectNLogToLoggingPanel(); Task.WaitAll(Task.Delay(100000000));
  • Use await Task.Delay instead of Task.WaitAll (the latter is blocking).
  • Any chance this could be implemented into LINQPad proper? That is, being able to dump to different target output panels, preferably with full support and functionality of the regular output panel.

    I have some scripts where I would like to have some processes running in parallel (invoked via Parallel.ForEach()) and output to their own separate panels status and other information and I can freely switch between the panels as they are running. I can kinda simulate it outputting dump containers for each batch but it gets messy trying to view the results from each batch.

Sign In or Register to comment.