Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7510213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:09:43+00:00 2026-05-29T23:09:43+00:00

C# in MS Visual Studio 2010. I am writing output to a log file

  • 0

C# in MS Visual Studio 2010. I am writing output to a log file as part of some code verification. The debugger shows the groups are getting the proper match, as does the Match output. The only thing that is wrong is the output file and I don’t know why. Here is the output I get from the file, where readline is the input line, Match is the result of a Regex match and Slot/Port are the result of getting values from named groups in the Regex. You can see from the log that the Regex Match matches the input line. The debugger says the Named Groups are working.

readline is: fc1/1 is up
Match is: fc1/1 is
Slot and Port are: 1/1
readline is: fc1/3 is up
Match is: fc1/3 is
Slot and Port are: 1/1

Here is the code that does the match – there is some extra stuff I added just to make it easier to watch in the debugger.

if (RegexExtensions.TryMatch(out InterfaceMatch, trimmed, InterfaceMatchString))
                {
                    SlotNum = Convert.ToInt32(InterfaceMatch.Groups["slot"].Value);
                    PortNum = Convert.ToInt32(InterfaceMatch.Groups["port"].Value);
                    string slot = InterfaceMatch.Groups["slot"].Value;
                    string port = InterfaceMatch.Groups["port"].Value;
  // write the value of current incoming readline
                  CiscoDecodeVariables.swlog.WriteLine(String.Format("readline is: {0}", readline));
 // write the value of the current match
                  CiscoDecodeVariables.swlog.WriteLine(String.Format("Match is: {0}", InterfaceMatch.Value.ToString()));
                  string slotasstring = SlotNum.ToString();
                  string portasstring = PortNum.ToString();
   // here is the line that writes what the slot and port values are
               CiscoDecodeVariables.swlog.WriteLine(String.Format("Slot and Port are: {0}/{0}", slotasstring, portasstring));
                CiscoDecodeVariables.swlog.Flush();
                    //sw.Close();
                    currPort = ((PortModule)ModuleList[SlotNum]).FCPortList[PortNum - 1];
                }

Finally, here is the code for the StreamWriter. I decleared a static class with a static variable so I can use the Streamwriter where I need to.

static public class CiscoDecodeVariables
{
    static public string LogFileOutPutPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\\ciscodecodelog.txt";
    static public StreamWriter swlog = new StreamWriter(LogFileOutPutPath);

}

Adding the RegEx match pattern in question
string InterfaceMatchString = @”fc(?\d+)/(?\d+) is”;

Also, the RegexExtensions.TryMatch() is a static method that returns true for a successful match and sets the InterfaceMatch instance to the result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:09:44+00:00Added an answer on May 29, 2026 at 11:09 pm

    It’s a problem with your format string.

    CiscoDecodeVariables.swlog.WriteLine(String.Format("Slot and Port are: {0}/{0}", slotasstring, portasstring)); 
    

    “{0}/{0}” means that you’ll get the result “slotasstring/slotasstring” rather than “slotasstring/portasstring”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing some unit tests in Visual Studio 2010. I can run all
I'm writing a visual web part in visual studio for sharepoint 2010. The whole
I'm writing some HBO for Internet Explorer in Visual Studio 2010. On my development
I am writing unit tests in visual studio 2010. For test some functionality, I
I recently found myself writing some XML in my Visual Studio 2010 Project's App.config
I am writing Python code in Visual Studio 2010 using the excellent Python Tools
Im writing a visual studio (2010) extension with a right click menu whilst in
I'm just writing a VSIX extension for Visual Studio 2010 and can't figure out
I am using Visual Studio 2010, and because of the amount of debug output
i'm writing a visual studio 2010 extension and got a ToolWindow with a ToolWindowToolbar.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.