A post on Virtualization

20. July 2006 12:19 by Jaguilar in General  //  Tags: ,   //   Comments (0)

This is a post from several months ago that I made on the 64–bit Advantage blog. Since now we’re working with virtualization (at the time it was only an interest of mine), I think it is worth it to re-post it here: 

I wanted to make a brief mention of the Virtualization Technology that is being introduced in the latest generation of Intel CPUs (known as VT-x). This technology was formerly known as "Vanderpool", and it is already available on some Pentium 4, Pentium D, Xeon and Core Duo CPUs. Later this year it will also be available on the next generation Itanium CPUs, using a technology known as "Silvervale".

I was talking with a coworker the other day about this technology, and our main question was "What is it exactly that it does? What advantage would it have over traditional software virtualization?" Well, to answer these two questions:

On a virtualization environment, there's the Virtual Machine Monitor (VMM), which handles the processor and physical resources of the machine, and the Guest Software, which operate inside a Virtual Machine handled by the VMM. VT-x introduces 10 new intructions to the architecture for facilitating the tasks of the VMM. Some of them, such as VMLAUNCH and VMRESUME, allow the VMM to start/enter running VMs, or VMON/VMOFF, turns the Virtualization functionality on and off.

The main reasons for using VT-x over software virtualization are speed and reliability. With hardware support, you are pretty much creating the equivalent of a hardware partition for the Guest Software, which improves both the performance and the robustness of the VM - and this is vital for consolidated server environments, one of the areas where VT-x is expected to be heavily used.

Now, one thing- why mention Intel's VT-x on this site? Well, one of the strenghts of 64-bit computing is that with more resources available on a single box, it is easier to to consolidate servers. With the new support for virtualization on the CPUs, you can use Virtual Machines for consolidation, so each software server has its own isolated environment without sacrificing performance.

 More information here.

Itanium with VT support thoughts and questions

20. July 2006 09:25 by Csaborio in General  //  Tags: ,   //   Comments (0)

After reading Jose's blog entry, I immediately had some questions about virtualization on the new dual-core Itanium architecture.  First and foremost, which software vendor out there has a Virtualization solution that supports the Itanium?  As far as I know, the roadmap for Virtual Server 2005 R2 SP1 does not include support for the Itanium.  Longhorn's roadmap does not include any foreseen support for the hypervisor on the Itanium either, so no luck in there as well.

Secondly, if some company indeed supported VT on the Itanium and allowed you to say, run Windows XP 32-bit on a virtual machine, would  that be faster than running the a 32-bit application directly on Windows Server for the Itanium?  Also, how would the WoW64’s performance (which IMHO is the Itanium's Achilles’ heel) be affected by the fact that there is VT support? 

These are many, many questions for which I have no answer for and hopefully will be addressed soon enough.

Montecito... err, Dual-Core Itanium 2 9000 series finally released

19. July 2006 16:25 by Jaguilar in General  //  Tags: , ,   //   Comments (0)

After several years of delays, the Dual-core Itanium 2, formerly known as Montecito, was unveiled by Intel. According to the press release:

They double the performance and lower energy requirements, improving performance per watt by 2.5 times compared to existing, single-core versions.
The Dual-Core Intel® Itanium® 2 processor 9000 series delivers performance at a system scale unmatched by competing RISC architectures. It set world record results in several key server benchmarks including a score of 4230 SPEC_int_rate_base_20001, nearly triple the previous record.

The CPU incorporates virtualization features, similar to the ones found on current-generation Intel x86 CPUs. My understanding is that neither Windows 2003 Server nor Viridian will support VT on the Itaniums, but my guess is that other vendors will, especially with the enhanced CPU horsepower and memory capability of this boxes.
Also, according to the press release, the Itanium Solutions Alliance is working on new system and applications that will leverage the power of this new CPU. We've worked with the ISA in the past, for the Developer Days events,  in which we showed ISV how to port and optimize their applications for 64-bit Windows.

Link to the press release: New Dual-Core Intel® Itanium® 2 Processor Doubles Performance, Reduces Power Consumption 

Unlimited virtualization not only for Longhorn anymore

19. July 2006 09:55 by smurillo in General  //  Tags:   //   Comments (0)

Microsoft first announced on October 10, 2005 that Windows Server "Longhorn" Datacenter Edition would give customers the right to run an unlimited number of virtual instances on a physical server. At the same time they said that with a single license of Windows Server 2003 R2 Enterprise Edition, customers could now run up to four virtual instances. You can access the full press pass here.

That was a significantly good announcement for customers. Those who use Windows Server 2003 R2 Enterprise Edition would get to try the benefits of virtualization. If it became necessary to run more than four instances they could eventually give into temptation and look for an expansion by purchasing the Windows Server "Longhorn" Datacenter Edition. Good strategy!

On July 12, Microsoft decided to improve this offer and shock the customers a bit more, and then some more. Starting October 1, 2006, new servers licensed with Windows Server Datacenter Edition would be entitled to run an unlimited number of virtualized Windows Server instances, including Standard, Enterprise and Datacenter Editions. Multiply them and mix them up as you wish.

This is not the only change made by Microsoft in order to promote their Windows Server Datacenter Editions. Want to know what else they did? Read the full announcement here.

Compacting a Dynamic VHD image

13. July 2006 02:21 by Jaguilar in General  //  Tags:   //   Comments (0)

One of the nicest features of using Dynamic VHDs on Virtual Server 2005 is that they grow as needed, so system administrators can optimize the disk space usage between several VMs. Dynamic VHDs grow automatically, but they don’t shrink automatically. In order to shrink them, you need to run several tools both inside and outside of the virtual machine.

Recently, I installed Windows Vista Beta 2 on a virtual machine on Virtual Server. Right after the installation, this are the disk usage stats:

compact1

Inside the virtual machine, however, the total disk space usage was smaller:

compact2

In order to compact the VHD image to only use the ~9GB allocated, we need to follow this procedure:

The first step is to defragment the VHD you are going to compact. You do this from within the Virtual Machine. Once the defragmentation is completed, you need to run Virtual Server’s Precompactor. To do this, mount the  image on the virtual machine from the Virtual Server console:

compact4

The precompactor will then execute and leave the VHD ready for compaction:

compact5compact6

If you are running the precompactor under Vista, remember to do a “Run as administrator”. Otherwise it won’t work.
This process may (will) take a long time, so be patient.

Once it completes, you need to shut down the virtual machine, and compact the VHD from the Virtual Server web console. This can be done from the option Virtual Disks->Inspect, then select the correct VHD on the Known virtual hard disks drop-down box, and click on the Inspect button. Then select the link to Compact Virtual Hard Disk:

compact7

You need to click on the Compact button on the next screen, and the process will then start. This will also take a while, but once it finished, you will reclaim all the hard drive space from your VHD file!

Virtual Server 2005 Migration Toolkit on x64 server

12. July 2006 13:22 by Jaguilar in General  //  Tags:   //   Comments (0)

Yes, it is sad but true. You cannot install the Virtual Server 2005 Migration Toolkit on an x64 server:

VSMT

What this means is that you need to have an intermediate 32–bit Windows 2003 installation running Virtual Server in order to convert a physical server to a virtual one. Hopefully x64 server will be soported in the near future.

Here is a post that talks about this: ADS 1.1 and VSMT on 64-bit hosts

 

Virtual PC 2004 is now free

11. July 2006 23:00 by Jaguilar in General  //  Tags:   //   Comments (0)

Virtual PC 2004 Service Pack 1 is now offered as a free download. From the webpage:

Whether Microsoft virtualization technology is an important component of your existing infrastructure or you're just a Virtual PC enthusiast, you can now download Virtual PC 2004 Service Pack 1 absolutely free. Microsoft is also offering the free download of Virtual PC 2007, with support for Windows Vista in 2007.

Hopefully this will further increase the adoption of virtualization technology.  I can’t wait for VPC2007 for it to support for hardware virtualization, like Virtual Server 2005.

Sysprep is your friend (for deploying pre-configured virtual machines)

7. July 2006 10:16 by Jaguilar in General  //  Tags:   //   Comments (0)

Most you I guess have heard about Sysprep, Microsoft’s System Preparation Tool. This tool removes certain information from a system, including the Security Identifier, IP address, computer name, etc. This is recommended when you are cloning a machine, and, by removing this information, you also remove any potential conflicts when starting up the cloned image for the first time.

When working with Virtual Machines, Sysprep is a real timesaver. You can, on a virtual machine, install several configurations of servers (Win2003EE/SQLServer2005, Win2003EE/IIS6.0, etc), sysprep the images, and then have these pre-configured images ready to deploy to a Virtual Server 2005 installation when needed, by just copying the appropriate VHD file over and associating it with a new VM.

In order to run Sysprep, you first need to install it. You can get a hold of Sysprep in two ways: it is on the \Support\Tools\Deploy.cab file on the Windows Server installation media, or you can download it from here. Once you get a hold of the Deploy.cab file, you should extract the contents to a directory on your HD, for example c:\Deploy.

SYSPREP1

This directory contains several useful tools, and you should definitely read the deploy.chm file for instructions and details on the process. There are two files that are of particular importance to the process: sysprep.exe and setupmgr.exe.

For sysprep to work completely automated, it requires an answer file, called sysprep.inf. This answer file contains the “answers” to all the questions asked by the Windows installer during the setup process. The answer file can be created manually with any text editor, but fortunately there is a nice wizard-like tool that can help you generate this file. This tool is the setupmgr.exe program:

SYSPREP2

This program allows you to generate the sysprep.inf file by presenting you the options and letting you enter the default answer. In order to fully automate an installation, follow these steps on the Setup Manager:

  1. Click Next on the Welcome screen
  2. Select “Create new” and click “Next”
  3. Select “Sysprep setup” and click “Next”:
    SYSPREP2a
  4. Select the type of system you’re going to sysprep, and click “Next”
  5. Select “Yes, fully automate the installation” and click “Next”
  6. Now you need to fill in all the information required to complete the process:
    SYSPREP2b

Once you complete the execution of the Setup Manager, it creates a new directory in the root of the system drive called sysprep. This directory contains all the information necessary for the Sysprep tool to execute.

SYSPREP4

Now you need to execute the Sysprep tool, sysprep.exe:

In this tool:

  1. Click “OK” on the warning dialog that appears when running the tool.
  2. Select “Don’t reset grace period for activation”
  3. Set the “Shutdown mode” to “Shut down”
  4. Click on Reseal. That will leave the image ready for copying.

Once the image is copied, you can just configure a new virtual machine with the new image, and start it up. The last portion of the Windows setup process will execute:
SYSPREP5

After a little while (<10min), the machine will reboot, and the process will be completed. You now have a brand new sysprep’d and cloned server up and running!!

 

Network Connections not showing the Virtual Machine Networking Service

6. July 2006 08:09 by Jaguilar in General  //  Tags:   //   Comments (0)

I just had my first “issue” with Virtual Server 2005 R2. I was trying to create a virtual network with access to the outside world, but I couldn’t get the physical NICs to appear under the "Network adapter on physical computer:" option on the "Network Properties" screen. I could only get the “None (Guests Only) option, as shown here:
NICSTEP0

Now, before anyone says anything, I know that in order to have them appear here, I first need to enable the "Virtual Machine Networking Service" on the NICs that I want to share. The service, however, was not showing up on the network properties on the NIC connected to the network:

NICSTEP1

On the Virtual Server Event log, I was getting the following error logged:

"Virtual Server could not open its emulated Ethernet switch driver. To fix this problem, re-enable the Virtual Server Emulated Ethernet Switch service on one or more Ethernet adapters or reinstall Virtual Server."

Before going for the obvious, I first did a quick scan of the net for that log message and for the error in general, and the recommendation I found on several forums was to re-enable the service (not possible, wasn’t appearing), or to reinstall the server. Well, it turns out that the solution was VERY, VERY easy: just re-installing the service on the adapter did the trick. To do this, follow these steps:

  1. Open the network connection properties page
  2. Click on the “Install…” button
  3. Select the “Service” option under the “Select Network Component Type” window, and click “Add…”
    NICSTEP2
  4. Now you need to select the "Virtual Machine Networking Service" from the selection window:
    NICSTEP3
  5. In case you don’t see this service on the window, you need to reinstall it. To do this, click no “Have Disk…”, then “Browse…”, and browse to the Virtual Server Installation directory\Drivers and select either the x86 OR x64 directory (depending on your installation):
    NICSTEP3A
  6. Then select the file “VMNetSrv.inf” to install the server:
    NICSTEP3B
  7. The service should now show up under the Network Connection properties:
    NICSTEP4

For some reason, the service is not installed on the adapters by deafult. With this process, however, the error messages go away, and you should be able to select the adapter on the “Network Properties" screen without having to re-install Virtual Server.

My first virtual machine...

5. July 2006 07:56 by Jaguilar in General  //  Tags:   //   Comments (0)

… On Virtual Server 2005 R2.

I installed FreeDOS in a new VM in about 5 minutes to test out the installation and the management tools.

dosvm

From now on, we are going to be working on several interesting projects related to virtualization, specifically to Virtual Server 2005 and the virtualization features coming up in Longhorn Server. I added a new category, Virtualization, where I’ll post any interesting bits of info I come accross. Make sure to check it out every once in a while.

 

64-bit Windows Server migration stories

3. July 2006 09:57 by Jaguilar in General  //  Tags: ,   //   Comments (0)

We’ve been working during the past two years on 64–bit awareness and helping customers move to the platform. I posted some time ago, on the 64–bit Advantage blog, about the migration of MySpace to 64–bit Windows Servers. Well, I just noticed that there is another story out (has been out for a few months, actually) about the migration of microsoft.com to x64 servers. Pretty interesting read. Take a look at the performance improvements they saw – they were impressive, especially the improvement in the response time.

You can read check it out here.

Questions on the VB Webcasts

30. June 2006 04:13 by Jaguilar in General  //  Tags:   //   Comments (0)

During the Visual Basic webcasts we get several questions, not all of them related to VB migrations. Following the 64–bit webcast’s lead, I think it would be a good idea to share them with you (they were originally asked in spanish, this is my rough translation):

Question: What happens with VB6 applications that use Spread?
Answer: FarPoint's Spread is a widely-used spreadsheet component used in VB6 applications. The current version of the Upgrade Wizard does not support the automated conversion of this component to the .NET equivalent. If you wish to continue using it, you’ll need to use COM interop. There’s a chance that a future version of the VB Upgrade Companion Edition will be able to convert this component.

Question: Does the Upgrade Wizard work for upgrading ASP applications?
Answer: No, it doesn’t. For ASP applications, there is the ASP to ASP.NET Migration Assistant. You can also check out the ASP to ASP.NET v1.x Migration Guide. It is slightly outdated and doesn’t deal with the 2.0 Framework, but should work as a good starting point.
Artinsoft also offers complete migration services for upgrading your ASP application to ASP.NET.

Question: Is there a solution for migration from Visual Foxpro to .NET?
Answer: Unfortunately there is no tool for migrating Visual Foxpro applicationsto the .NET Framework.

Question: Is there a document with and outline of the testing process for migration projects?
Answer: The testing process depends on the type of application. There is no “magic bullet” that will describe this. There is, however, a migration guide, developed between ArtinSoft and Microsoft, that has a chapter on testing the applications. This can be found at Upgrading Visual Basic 6.0 Applications to Visual Basic .NET and Visual Basic 2005.
ArtinSoft also recomends using a slightly modified version of the original application’s test cases.

Question: What version of the .NET Framework is required for the migration tool?
Answer: The Upgrade Wizard is available for version 1.0, 1.1 and 2.0 of the .NET Framework. We are currently using the version bundled with Visual Studio .NET 2005, that uses version 2.0 of the Framework, because it is the most recent version.

Remember to check out all the VB to VB.NET presentations, that can be found at the CEM website.

Pictures from the Santiago Event

29. June 2006 11:28 by Jaguilar in General  //  Tags:   //   Comments (0)

Here are some pictures of the event last week in Santiago.

Asistentes al Evento 4 Asistentes al Evento 2

 Asistentes al Evento 1 Jose presentando 2

 BTW, this is my first post with BlogJet. Nice tool.

Final CEM Visual Basic webcast

29. June 2006 08:24 by Jaguilar in General  //  Tags: ,   //   Comments (0)

Tomorrow I'll be doing the final Webcast in a series about migrating from Visual Basic 6.0 to Visual Basic .NET. This one will be about tecniques on how to migrate common objects in Visual Basic (some controls, database access, forms, etc), and about recommendations on how to test a migrated application.

All in all, there were seven webcasts in the series. They were: (names in spanish...)

I suggest you check them out. :-)

Santiago, Chile, 64-bit Advantage event

29. June 2006 08:10 by Jaguilar in General  //  Tags: ,   //   Comments (0)

Last week we had the final scheduled 64-bit Advantage event in Santiago, Chile. It was an incredible success. The people and organization were really happy with the results. It is a shame that there are very few events like it in Latin America

One of the things that really caught my attention was the fact that there was a well-known (not to us) Linux user/advocate in the audience. The good thing is that he gave us a very positive review for the event, and mentioned that he was surprised of the professionalism we displayed when confronted with cross-platform questions, and how we even address the availability of certain technologies on other platforms (such as POSIX Threads, polymorphic types, etc).

By the way, if you have a chance, go and visit Santiago. It is a beautiful city, the people are amazing, and I can't even start talking about the food, especially seafood. Just remeber to visit Costa Rica first, of course. :-)

Thanks to Christian, Wilson, José, Katina, and the rest of the organization for the hard work and dedication that went into making this event happen!!

Questions from the first 64-bit Web Cast

28. June 2006 06:07 by Csaborio in General  //  Tags:   //   Comments (0)
So the webcast went very well, we had about 40 people who asked very interesting questions which I thought I would share with you.  The typing errors remain as I want the script to be the original one:

Question: Is there any general 64-coding info for starters?
Answer: You can find all kinds of programming info (C++/Managed Code, etc.) on http://www64advantage.com. It is one of the best places to start.

Question: does c# work on 64-bit at this moment?
Answer: Yes, C# and Visual Basic .Net are fully supported in 64-bit with the release of the 2.0 64-bit framework.

Question: Will this webcast be available for download?
Answer: yes in 24 hours at www.microsoft.com/webcasts

Question: From the Developers Perspective, What would be the learning curve from 32 bit programing to 64bit programing?
Answer: It really depends on your programming language. If you are dealing with managed code, oftentimes things can be as easy as just recompiling. With languages such as C++, the API has not changed that much, so given that you watch out for common pitfalls, your 64-bit learning curve should not very steep.

Question: Do we have to sign up for tomorrow's session or are we already registered ?
Answer: You need to sign up for each of the webcasts. The information for tomorrow's webcast: http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032299373&EventCategory=4&culture=en-US&CountryCode=US

Question: I am running XP Pro at home. Can I write 64-bit code without a server?
Answer: You definitely can. Visual Studio and the PSDK will allow you to write 64-bit executables from a 32-bit OS (Server or XP). Remember to always use /wp64!


New Series of 64-bit Related Web Casts

28. June 2006 04:14 by Csaborio in General  //  Tags:   //   Comments (0)
Starting today (like in 30 minutes ;) ), we will start the first webcast in a series of three.  These revolve around most of the things we have discussed in the labs plus some new ones such as issues with 64-bit installers, setting up VS for 64-bit deployment, and multi-threading your application using OpenMP standards.

You can find the whole list here.  Tomorrow, Thursday 29th, I will be presenting a webcast that has many, many demos on how to preserve dependencies in 64-bit.  Feel free to stop by and let me know your comments once the session is over.

If you really have no idea on what to expect when moving to 64-bit, then these webcasts are definitely worth listening to.

Lower Bounds not 0 in VB.NET

14. June 2006 17:31 by Mrojas in General  //  Tags:   //   Comments (0)
The other day a friend asked me. How could he created an array in VB with a lower bound different from 0.

In VB6 you could do something just like this:

Dim b(6 To 12) As Integer 

But in VB.NET it does not work that way. The LowerBound in VB.NET must be always 0. But there is a way to have a lower bound different from 0. It is unclear why this is not very documented but the following code shows how to do it: 

Dim b As Array = Array.CreateInstance(GetType(String), New Integer() {6}, New Integer() {6})

b(6) = 20

b(7) = 1

 

I received this comment:

Hi Mauricio RojaI am converting the VB6 programs to VB.Net2008. When I declare the array in VB.Net the lower bound always "0". When I searched internet got some clue from you. Thanks.Could you please help me to solve the array problem. I have declared a array as "public socketbins(1 to DUT, 1 to SOCK, 1 to 1000) as CBin" in VB6. When I convert this declaration to VB.Net2008 it is not accepted. can you please tell me how to declare the above declaration in VB.Net2008Thanks & RegardsUdhay

And this is my answer:

 

Hi.

Sorry for my late response.

I don’t know what you mean for CBin

But let's says the array type is byte

Then you can do this:

Dim socketBins4 = Array.CreateInstance(GetType(Byte), New Integer() {DUT, SOCK, 1000}, New Integer() {1, 1, 1})

And I am sending some code for your tests

 

Module Module1

Const DUT = 100

Const SOCK = 100

'taken and modified from http://blogs.msdn.com/vbfaq/archive/2004/04/20/116660.aspx

Public Class VBArray(Of T)

Private _lbound As Integer

Private _myitems() As T

Public Sub New(ByVal LBound As Integer, ByVal UBound As Integer)

Me.ReDim(LBound, UBound)

End Sub

Public Sub [ReDim](ByVal LBound As Integer, ByVal UBound As Integer)

_lbound = LBound

ReDim _myitems(UBound - LBound + 1)

End Sub

Default Public Property Item(ByVal Index As Integer) As T

Get

Return _myitems(Index - _lbound)

End Get

Set(ByVal Value As T)

_myitems(Index - _lbound) = Value

End Set

End Property

Public Function ToArray() As T()

Return _myitems

End Function

End Class

Sub Main()

 

Dim socketBins4 = Array.CreateInstance(GetType(Byte), New Integer() {DUT, SOCK, 1000}, New Integer() {1, 1, 1})

Dim arrayLenghts() As Integer = {DUT, SOCK, 1000}

Dim arrayLowerBounds() As Integer = {1, 1, 1}

Dim socketBins3 = Array.CreateInstance(GetType(Byte), arrayLenghts, arrayLowerBounds)

socketBins3(1, 1, 1) = 10

MsgBox("LBound for FirstDimension = " & LBound(socketBins3, 1))

MsgBox("LBound for SecondDimension = " & LBound(socketBins3, 2))

MsgBox("LBound for ThirdDimension = " & LBound(socketBins3, 3))

 

MsgBox("UBound for FirstDimension = " & UBound(socketBins3, 1))

MsgBox("UBound for SecondDimension = " & UBound(socketBins3, 2))

MsgBox("UBound for ThirdDimension = " & UBound(socketBins3, 3))

 

socketBins3(0, 0, 0) = 10 ' <--- This will throw an exception

 

'This are other possibilities

'This is not possible Dim socketbins(1 to DUT, 1 to SOCK, 1 to 1000) as Byte

Dim socketbins(0 To DUT, 0 To SOCK, 0 To 1000) As Byte

Dim socketBins2 As New VBArray(Of VBArray(Of VBArray(Of Byte)))(1, DUT)

'And then some init code here

 

End Sub

End Module

 

More Color to your Traces!

29. May 2006 08:37 by Mrojas in General  //  Tags: , ,   //   Comments (0)

Most Visual Basic programmers are familiar with using Debug.Print to follow their code's execution. The .NET environment introduces Tracing falicities that allows you to send messages to files or the console.

However the console output could be improved by using colors to highlight certain events. 
I developed a simple ColorTraceListener that can be used either with the My.Application.Log object or the Trace.TraceXXX methods. 
I first thing to do is create a ClassLibrary. It will be called ColorTraceListener. Add a ColorTraceListener.cs File and fill it with the following code:
 

Imports System

Imports System.Diagnostics

Imports System.Globalization

Imports System.Text

Imports System.Runtime.InteropServices 

Public Class ColorTraceListener

    Inherits ConsoleTraceListener

    Public Sub New()

        MyBase.New()

    End Sub 

    Public Sub New(ByVal useErrorStream As Boolean)

        MyBase.New(useErrorStream)

    End Sub 

    Friend Function IsEnabled(ByVal opts As TraceOptions) As Boolean

        Return ((opts And Me.TraceOutputOptions) <> TraceOptions.None)

    End Function 
 
 

    False)> _

    Public Overrides Sub TraceData(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal data As Object)

        If ((Me.Filter Is Nothing) OrElse Me.Filter.ShouldTrace(eventCache, source, eventType, id, Nothing, Nothing, Nothing, data)) Then

            Me.WriteHeader(source, eventType, id)

            Dim text1 As String = String.Empty

            If (Not data Is Nothing) Then

                text1 = data.ToString

            End If

            Me.WriteLine(text1)

            Me.WriteFooter(eventCache)

        End If

    End Sub 

    False)> _

    Public Overrides Sub TraceData(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal ParamArray data As Object())

        If ((Me.Filter Is Nothing) OrElse Me.Filter.ShouldTrace(eventCache, source, eventType, id, Nothing, Nothing, Nothing, data)) Then

            Me.WriteHeader(source, eventType, id)

            Dim builder1 As New StringBuilder

            If (Not data Is Nothing) Then

                Dim num1 As Integer = 0

                Do While (num1 < data.Length)

                    If (num1 <> 0) Then

                        builder1.Append(", ")

                    End If

                    If (Not data(num1) Is Nothing) Then

                        builder1.Append(data(num1).ToString)

                    End If

                    num1 += 1

                Loop

            End If

            Me.WriteLine(builder1.ToString)

            Me.WriteFooter(eventCache)

        End If

    End Sub 
 

    False)> _

    Public Overrides Sub TraceEvent(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal message As String)

        If ((Me.Filter Is Nothing) OrElse Me.Filter.ShouldTrace(eventCache, source, eventType, id, message, Nothing, Nothing, Nothing)) Then

            Me.WriteHeader(source, eventType, id)

            Me.WriteLine(message)

            Me.WriteFooter(eventCache)

        End If

    End Sub 
 

    False)> _

    Public Overrides Sub TraceEvent(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal format As String, ByVal ParamArray args As Object())

        If ((Me.Filter Is Nothing) OrElse Me.Filter.ShouldTrace(eventCache, source, eventType, id, format, args, Nothing, Nothing)) Then

            Me.WriteHeader(source, eventType, id)

            If (Not args Is Nothing) Then

                Me.WriteLine(String.Format(CultureInfo.InvariantCulture, format, args))

            Else

                Me.WriteLine(format)

            End If

            Me.WriteFooter(eventCache)

        End If

    End Sub 
 
 
 
 

    Private Sub WriteFooter(ByVal eventCache As TraceEventCache)

        If (Not eventCache Is Nothing) Then

            Me.IndentLevel += 1

            If Me.IsEnabled(TraceOptions.ProcessId) Then

                Me.WriteLine(("ProcessId=" & eventCache.ProcessId))

            End If

            If Me.IsEnabled(TraceOptions.LogicalOperationStack) Then

                Me.Write("LogicalOperationStack=")

                Dim stack1 As Stack = eventCache.LogicalOperationStack

                Dim flag1 As Boolean = True

                Dim obj1 As Object

                For Each obj1 In stack1

                    If Not flag1 Then

                        Me.Write(", ")

                    Else

                        flag1 = False

                    End If

                    Me.Write(obj1.ToString)

                Next

                Me.WriteLine(String.Empty)

            End If

            If Me.IsEnabled(TraceOptions.ThreadId) Then

                Me.WriteLine(("ThreadId=" & eventCache.ThreadId))

            End If

            If Me.IsEnabled(TraceOptions.DateTime) Then

                Me.WriteLine(("DateTime=" & eventCache.DateTime.ToString("o", CultureInfo.InvariantCulture)))

            End If

            If Me.IsEnabled(TraceOptions.Timestamp) Then

                Me.WriteLine(("Timestamp=" & eventCache.Timestamp))

            End If

            If Me.IsEnabled(TraceOptions.Callstack) Then

                Me.WriteLine(("Callstack=" & eventCache.Callstack))

            End If

            Me.IndentLevel -= 1

        End If

    End Sub 

    Private Sub WriteHeader(ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer)

        Dim oldColor As ConsoleColor = Console.ForegroundColor

        Select Case eventType

            Case TraceEventType.Error

                Console.ForegroundColor = ConsoleColor.Red

            Case TraceEventType.Critical

                Console.ForegroundColor = ConsoleColor.Magenta

            Case TraceEventType.Information

                Console.ForegroundColor = ConsoleColor.White

                'Case TraceEventType.Resume

                'Case TraceEventType.Start

                'Case TraceEventType.Suspend

                'Case(TraceEventType.Transfer)

                'Case TraceEventType.Verbose

            Case TraceEventType.Warning

                Console.ForegroundColor = ConsoleColor.Yellow

        End Select

        Me.Write(String.Format(CultureInfo.InvariantCulture, "{0} {1}:", New Object() {source, eventType.ToString}))

        Console.ForegroundColor = oldColor

        Me.Write(String.Format(CultureInfo.InvariantCulture, " {0} : ", New Object() {id.ToString(CultureInfo.InvariantCulture)}))

    End Sub

End Class 

The methods that handle the headers in the TextWriteListener are private (WriteHeader and WriterFooter) so we need to override them. Reflector comes very handy in this cases. 

No to test it Create a Vb Console Application: 

Module Module1 

    Sub Main() 
 

        My.Application.Log.WriteEntry("Error!", TraceEventType.Error)

        My.Application.Log.WriteEntry("Warning", TraceEventType.Warning)

        My.Application.Log.WriteEntry("Info", TraceEventType.Information)

        My.Application.Log.WriteEntry("Info", TraceEventType.Critical) 

        Trace.TraceError("An Error Happened!")

        Trace.TraceInformation("Just letting you know!")

        Trace.TraceWarning("Watch the road ahead") 

    End Sub 

End Module 

And use a simple configuration file like the following: 

xml version="1.0" encoding="utf-8" ?>

<configuration>

    <system.diagnostics>

      <trace autoflush="true">

        <listeners>

          <add name="ColorLog" />

        listeners>

      trace>

        <sources>

            This section defines the logging configuration for My.Application.Log -->

            <source name="DefaultSource" switchName="DefaultSwitch">

                <listeners>

                    <add name="ColorLog"/>

                listeners>

            source>

        sources>

        <switches>

            <add name="DefaultSwitch" value="Verbose" />

        switches>

       <sharedListeners>

          <add name="ColorLog" type="Mrojas.ColorTraceListener, ColorTraceListener" />

        sharedListeners>

    system.diagnostics>

configuration> 
 

HP and Intel Developer Workshop in Seattle

29. May 2006 05:29 by Jaguilar in General  //  Tags: ,   //   Comments (0)

In a couple of weeks I'll be teaching some of the lessons at the HP and Intel Developer Workshop in Seattle, WA. The workshop will take place on June 13-15. As with the previous workshop, in Dallas, this is a great oppotunity to port your code to 64-bit windows on the Itanium platform. You'll be surprised that it may be easier to port your source code than it looks - in Dallas we had a guy that ported his code in about an hour! Then again, we've been working with a company for about two years on the port - can't tell you who it is, but if you knew, you'll see why it is taking so long.

The Workshop has all sorts of nice perks. In addition to the quality training given by yours truly and my coworkers, you can also also take with you the Itanium server that you use during the class. You can read all the benefits about it on the Workshop's web page.

Categories