Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. log4net doesn't log in myProcess.OutputDataReceived

log4net doesn't log in myProcess.OutputDataReceived

Scheduled Pinned Locked Moved C#
debugginghelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    buchstaben
    wrote on last edited by
    #1

    Hi, my app logs correctly while code is beeing executed within my method DoIt. But it doesn't log in the Process.OutputDataReceived's EventHandler even if p_OutputDataReceived is called. Is there anything I need to look at while using Process?

        private void DoIt(string arguments)
        {
            \_log.Fatal("TEST"); // DOES LOG
            Process p = new Process();
            p.StartInfo.FileName = @"D:\\vssTOOLS\\NetJobs\\UpdateDealArchiveInstrSeq\\UpdateCaller\\bin\\Debug\\UpdateDealArchiveInstrSeq.exe";
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.OutputDataReceived += new DataReceivedEventHandler(p\_OutputDataReceived);
            p.ErrorDataReceived += new DataReceivedEventHandler(p\_ErrorDataReceived);
            p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Caller)).Location);
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.Arguments = arguments;
            p.Start();
    
            p.BeginOutputReadLine();
            p.BeginErrorReadLine();
    
            p.WaitForExit();
    
            //Synchronisieren
            do
            {
                System.Threading.Thread.Sleep(100);
            } while (!p.HasExited);
    
            if (p.ExitCode != 0)
            {
                // DOES LOG
                for (int i = 0; i < procOut.ToString().Length; i += 2000)
                    \_log.Info(procOut.ToString().Length > i + 2000 ? procOut.ToString().Substring(i, 2000) : procOut.ToString().Substring(i));
                for (int i = 0; i < procErr.ToString().Length; i += 2000)
                    \_log.Error(procErr.ToString().Length > i + 2000 ? procErr.ToString().Substring(i, 2000) : procErr.ToString().Substring(i));
                throw new ApplicationException("Es ist ein Fehler aufgetreten: " + procErr.ToString());
            }
        }
    
        StringBuilder procOut = new StringBuilder();
        StringBuilder procErr = new StringBuilder();
        void p\_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            procErr.AppendLine(e.Data);
            \_log.Error(e.Data); // DOES NOT LOG
        }
    
        void p\_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            procOut.AppendLine(e.Data);
            \_log.Info(e.Data); // DOES NOT LOG
        }
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups