NLog control to an existing RichTextBox Windows Form

后端 未结 5 961
醉梦人生
醉梦人生 2021-01-13 01:21

Below is my NLog configuration, I want to load log into existing RichTextBox called rtMessage in Form1, but NLog will create a new windows with log message loaded into the R

5条回答
  •  心在旅途
    2021-01-13 01:52

    1.normally init logger in winform1_Load while it have done InitializeComponent -> has init your own RichTextBox.

    2.then makesure your RichTextBoxTarget's FormName and ControlName initialized ok. such as:

    RichTextBoxTarget rtbTarget = new RichTextBoxTarget();
    logConfig.AddTarget("richTextBox", rtbTarget);
    rtbTarget.FormName = "frmScrapeAmazonProduct"; // your winform class name
    rtbTarget.ControlName = "rtbLog"; // your RichTextBox control/variable name
    

    more can refer my post

提交回复
热议问题