[STAThread] // for file dialog boxes
        static void Main(string[] args)
        {
            var config        = new NLog.Config.LoggingConfiguration();
            var easyToReadLog = "${level:uppercase=true}: ${message}";

            var rtbTarget = new NLog.Windows.Forms.RichTextBoxTarget(); // garbage documentation from NLog - need nuget Nlog and Nlog.windows.forms

            rtbTarget.TargetForm                 = gui;
            rtbTarget.TargetRichTextBox          = gui.logBox;
            rtbTarget.UseDefaultRowColoringRules = true;
            rtbTarget.Layout = easyToReadLog;

            // Targets where to log to: File and Console
            var logfile = new NLog.Targets.FileTarget("logfile")
            {
                FileName = "log.txt"
            };
            var logconsole = new NLog.Targets.ColoredConsoleTarget("logconsole");

            logconsole.Layout = easyToReadLog;
            logconsole.UseDefaultRowHighlightingRules = true;
            logfile.Layout = "${longdate} |" + easyToReadLog;


            // Rules for mapping loggers to targets
            config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);

            config.AddRule(LogLevel.Info, LogLevel.Fatal, rtbTarget);
            NLog.LogManager.Configuration = config;

            log.Info("Program started");

            gui.ShowDialog();
        }
Exemple #2
0
        private async void StartAnalysisButton_Click(object sender, EventArgs e)
        {
            CancelButton.Enabled        = true;
            StartAnalysisButton.Enabled = false;


            NLog.Windows.Forms.RichTextBoxTarget rtbTarget = new NLog.Windows.Forms.RichTextBoxTarget();
            LogManager.Configuration = new LoggingConfiguration();

            rtbTarget.ControlName = "LogBox";
            LogManager.Configuration.AddTarget("LogBox", rtbTarget);

            //LogManager.ReconfigExistingLoggers();

            _cts = new CancellationTokenSource();
            var token = _cts.Token;

            try
            {
                await Task.Run(() =>
                {
                    AnalyseSample();
                });
            }
            catch (OperationCanceledException)
            {
                StartAnalysisButton.Enabled = true;
                CancelButton.Enabled        = false;
            }
        }