locked
Log info RRS feed

  • Question

  • I am using this command to create a log file:

    NDP40-KB2487367-x86.exe /q /lv C:\..\..\Desktop\Log.txt

    I have tried this for the whole set of *.exe files and *.msu files and the log is not being created. even using *.exe /? is telling me to do this, so I'm not sure what I am doing wrong.

    Monday, January 21, 2013 12:11 AM

Answers

  • when running that command from the command line does it create the log?

    It could also be:
    sometimes I have had to put the command and the argument all into StartInfo.FileName and leave the argument property blank.



    unfortunately, no. That is actually my question. From what I am reating on the internet my syntax is correct. But it's just not creating the log.

    OK this is not a c# question then it is a windows question.  If the command does not properly work when you manually run it from a command line then there is no way you are going to get it to run in c# properly.

    Maybe you need to reinstall or upgrade your MSI engine?

    Reask in the Windows Server forums or.....

    • Proposed as answer by CountryStyle Monday, January 21, 2013 3:50 PM
    • Marked as answer by Bob Shen Monday, February 4, 2013 7:54 AM
    Monday, January 21, 2013 3:15 PM
  • You're sure, it's legal to mess with Security Update for Microsoft .NET Framework 4.0 (KB2487367)..?

    Classified SR-2 | 2x Xeon W5580 - 3.20 GHz | 12x 2GB Kingston KHX2000C9D3T1K3/6GX | 2x MARS II/2DIS/3GD5 | SAMSUNG 830 MZ-7PC512D/AM 2.5" 512GB SATA III MLC | 4x Spinpoint F3EG HD503HI 500GB 5400 16MB SATA 3.0Gb/s |

    • Marked as answer by Bob Shen Monday, February 4, 2013 7:54 AM
    Monday, January 21, 2013 5:32 PM

All replies

  • This is a C# programming forum.  Can you show us the code that you are using?


    Paul Linton

    Monday, January 21, 2013 2:50 AM
  • private void executeFile(string file)
            {
                //let WUSA.exe handle *.msu files
                if (file.Substring(file.LastIndexOf(".")).Equals(".msu"))
                {
                    try
                    {
                        using (Process process = new Process())
                        {
                            process.StartInfo.FileName = "wusa.exe";
                            process.StartInfo.Arguments = file + "/norestart /quiet /L*v " + file.Substring(0, file.LastIndexOf("\\")).Length + "Log.txt";
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            process.StartInfo.UseShellExecute = false;
                            process.StartInfo.RedirectStandardError = true;
                            process.StartInfo.RedirectStandardOutput = true;
                            process.OutputDataReceived += process_DataRecieved;
                            process.ErrorDataReceived += process_DataRecieved;
                            process.Start();
                            process.BeginOutputReadLine();
                            process.BeginErrorReadLine();
                            process.WaitForExit();
                        }
                    }
                    catch (Exception ex)
                    {
                        msg[1] = ex.Message;
                        //Thread.Sleep(1000); //give the thread time to recover from the error
                    }
                }
                //run *exe files in background
                else if (file.Substring(file.LastIndexOf(".")).Equals(".exe"))
                {
                    try
                    {
                        using (Process process = new Process())
                        {
                            process.StartInfo.FileName = file;
                            process.StartInfo.Arguments = "/quiet /L*v " + file.Substring(0, file.LastIndexOf("\\")).Length + "Log.txt";
                            process.StartInfo.CreateNoWindow = true;
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            process.StartInfo.UseShellExecute = false;
                            process.StartInfo.RedirectStandardError = true;
                            process.StartInfo.RedirectStandardOutput = true;
                            //process.OutputDataReceived += new DataReceivedEventHandler(process_DataRecieved);
                            //process.ErrorDataReceived += new DataReceivedEventHandler(process_ErrorReceived);
                            
                            process.Start();
                            msg[0] = process.StandardOutput.ReadToEnd();
                            msg[1] = process.StandardError.ReadToEnd();
                            process.WaitForExit();
                        }
                    }
                    catch (Exception ex)
                    {
                        msg[1] = ex.Message;
                    }

    Sorry about the formatting...the block wouldn't keep it. >.>

    • Edited by Shirotsuki Monday, January 21, 2013 3:38 AM
    Monday, January 21, 2013 3:34 AM
  • Where did you get that "NDP40- ..." command from?  It may be correct, I don't know.  Just because one program uses that syntax to create a log file does not mean that any other program does.

    In your first post you use show that the command uses /lv but in your code you have /l*v  I assume that one of these is a typo?  Which one, my guess is the one in the code is wrong.

    That file specification looks very odd to me.  Have you tried running your command from a command prompt?  Does it work?  What is your default directory?

    Why do you say that "*.exe /?" is telling me to do this?  When I type that command I just get an error.  what did you actually type and where to get this advice?

    In a nutshell, your request is very, very odd.  What are you trying to achieve?


    Paul Linton

    Monday, January 21, 2013 3:45 AM
  • when running that command from the command line does it create the log?

    It could also be:
    sometimes I have had to put the command and the argument all into StartInfo.FileName and leave the argument property blank.


    Monday, January 21, 2013 4:08 AM
  • If you are sure all the switches are correct for NDP40-KB2487367-x86.exe maybe it a rights issue running running it as a process from code.

    Try adding:

    process.StartInfo.Verb = "runas"

    This should run it with local administration rights.

    Monday, January 21, 2013 4:11 AM
  • Not sure why you are using this command to create log file, you can write simple c# code to create a txt file and write all log entries in that in your own defined format.

    OR

    You can use Microsoft Enterprise library for exception logging.. check this link for detail http://msdn.microsoft.com/en-us/library/ff648951.aspx


    Mark this post as answer if this resolves your issue.


    Everything about SQL Server | Experience inside SQL Server -Mohammad Nizamuddin

    Monday, January 21, 2013 4:46 AM
  • One of the most popular logging frameworks for C# nowadays is log4net. In this tutorial I'll show you how to configure it and how it works. This tool is open source and allows you to create various logs in different output targets. It's very similar to log4j - logging tool for Java. We'll configure it to work on the example of web application but it's almost the same to setup it for other Visual Studio projects.

    First step is to download log4net from their homepage: http://logging.apache.org/log4net/. Go to the download section and choose the most current version.

    Then after creating a new project in Visual Studio we have to add reference to log4net library. To do this go to the Solution Explorer window on right hand side and right-click on the References folder and click Add Reference.

    Then in the opened window choose Browse tab, find log4net dll file in the package that you just downloaded and click Add button.

    Now we'll configure web.config or app.config file depending on what type of project you're creating. Add to this file following code within <configuration> tag just in the beginning:

    1. <configSections>  
    2. <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>  
    3. </configSections>  
    4. <log4net>  
    5. <root>  
    6. <level value="DEBUG" /> <appender-ref ref="LogFileAppender" />  
    7. </root>  
    8. <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >  
    9. <param name="File" value="C:\temp\log.txt" />  
    10. <param name="AppendToFile" value="true" /> <rollingStyle value="Size" />  
    11. <maxSizeRollBackups value="10" /> <maximumFileSize value="10000" />  
    12. <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout">  
    13. <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss}  
    14. – %m%n" /> </layout> </appender>  
    15. </log4net>  

    Then we'll add local variable that will represent our logger. To do so add following code to you code-behind file:

    1. protected static readonly ILog logger = LogManager.GetLogger(typeof(<WBR>Global));  

    Now depending on the type of the project you created and the class you have to specify in this code type of your main class. So you have to put name of your class in typeof() method. In my case this name is Global.

    Finally we'll have to add following code to the code-behind file that runs on application startup, again the name of this method depends on the type of the project you are working on. In the case of web application it's Application_Start.

     

    1. log4net.Config.<WBR>XmlConfigurator.Configure();  
    2. log.Info("log4net is working correctly");  

    Now you can just run your application. This will create a new file: C:\temp\log.txt. There are 5 levels of messages in log4net:

      • Debug
      • Info
      • Warn
      • Error
      • Fatal

      You can add each of these wherever you need it. To see how it works add following code somewhere in your application:

      1. log.Debug("Debug log");  
      2. log.Info("Info log");  
      3. log.Warn("Warn log");  
      4. log.Error("Error log");  
  • log.Fatal("Fatal log");  

    After running such application, your log file should look like this:

    INFO 2011-07-16 01:48:50 – log4net is working correctly
    DEBUG2011-07-16 01:48:50 – Debug log
    INFO 2011-07-16 01:48:50 – Info log
    WARN 2011-07-16 01:48:50 – Warn log
    ERROR2011-07-16 01:48:50 – Error log
    FATAL2011-07-16 01:48:50 – Fatal log

    Summing up log4net is very useful tool for logging that you can use with different types of .NET applications.

Monday, January 21, 2013 5:15 AM
  • Where did you get that "NDP40- ..." command from?  It may be correct, I don't know.  Just because one program uses that syntax to create a log file does not mean that any other program does.

    In your first post you use show that the command uses /lv but in your code you have /l*v  I assume that one of these is a typo?  Which one, my guess is the one in the code is wrong.

    That file specification looks very odd to me.  Have you tried running your command from a command prompt?  Does it work?  What is your default directory?

    Why do you say that "*.exe /?" is telling me to do this?  When I type that command I just get an error.  what did you actually type and where to get this advice?

    In a nutshell, your request is very, very odd.  What are you trying to achieve?


    Paul Linton


    NDP40- ... is not a command, its a file. the program is to loop through a set of files and install them. (the looping part works). /lv is to log verbose, /l*v is to log everything. I deally, I would like to log what is happening into a window, and allow the user to save the log. But I figured first I would have to figure out how to create the log. This command does not work on the command line. I am looking into a different rout now (Log4Net), unless someone knows why it isnt working.
    Monday, January 21, 2013 2:10 PM
  • when running that command from the command line does it create the log?

    It could also be:
    sometimes I have had to put the command and the argument all into StartInfo.FileName and leave the argument property blank.



    unfortunately, no. That is actually my question. From what I am reating on the internet my syntax is correct. But it's just not creating the log.
    Monday, January 21, 2013 2:12 PM
  • Clarification: This program is to loop through a set of files (*.exe and *.msu) . These files are instalations/updates. My goal is to build a patcher to install these files if needed. If, say, it fails to install due to a current or later version already being installed, I would like to print this to the RichTextBox. Even if I can't get this part to work, I would like to atleast print a log to the folder that the install is in (each install is in its own folder).

    Monday, January 21, 2013 2:58 PM
  • Not sure why you are using this command to create log file, you can write simple c# code to create a txt file and write all log entries in that in your own defined format.

    OR

    You can use Microsoft Enterprise library for exception logging.. check this link for detail


    Mark this post as answer if this resolves your issue.



    Because i'm trying to log the progress of the instilation, which you can't just do manually. It has to print the log file based on weather or not the file installed correctly, and if not why.
    Monday, January 21, 2013 3:00 PM
  • when running that command from the command line does it create the log?

    It could also be:
    sometimes I have had to put the command and the argument all into StartInfo.FileName and leave the argument property blank.



    unfortunately, no. That is actually my question. From what I am reating on the internet my syntax is correct. But it's just not creating the log.

    OK this is not a c# question then it is a windows question.  If the command does not properly work when you manually run it from a command line then there is no way you are going to get it to run in c# properly.

    Maybe you need to reinstall or upgrade your MSI engine?

    Reask in the Windows Server forums or.....

    • Proposed as answer by CountryStyle Monday, January 21, 2013 3:50 PM
    • Marked as answer by Bob Shen Monday, February 4, 2013 7:54 AM
    Monday, January 21, 2013 3:15 PM
  • when running that command from the command line does it create the log?

    It could also be:
    sometimes I have had to put the command and the argument all into StartInfo.FileName and leave the argument property blank.



    unfortunately, no. That is actually my question. From what I am reating on the internet my syntax is correct. But it's just not creating the log.

    OK this is not a c# question then it is a windows question.  If the command does not properly work when you manually run it from a command line then there is no way you are going to get it to run in c# properly.

    Maybe you need to reinstall or upgrade your MSI engine?

    Reask in the Windows Server forums or.....


    Yeah I will. I wanted to ask here first to see if I could get an alternative way to my problem. Thanks though.
    Monday, January 21, 2013 3:38 PM
  • You're sure, it's legal to mess with Security Update for Microsoft .NET Framework 4.0 (KB2487367)..?

    Classified SR-2 | 2x Xeon W5580 - 3.20 GHz | 12x 2GB Kingston KHX2000C9D3T1K3/6GX | 2x MARS II/2DIS/3GD5 | SAMSUNG 830 MZ-7PC512D/AM 2.5" 512GB SATA III MLC | 4x Spinpoint F3EG HD503HI 500GB 5400 16MB SATA 3.0Gb/s |

    • Marked as answer by Bob Shen Monday, February 4, 2013 7:54 AM
    Monday, January 21, 2013 5:32 PM