Thanks. I will try to explain what I am doing so that you can try to figure what I was doing wrong. I have tried to work according to the instructions in the Hands on Tutorial for Enterprise Logging Application block. The exception of course being that
the code should be in C++/CLI instead of C#.
So let me retrace the steps:
- New->CLR Console Application
- Created a new project named EL Logger
The basic code for the class is this:
public ref class EL_Logger
void Write(String^ message)
int main(array<System::String ^> ^args)
EL_Logger ^logger = gcnew EL_Logger();
logger->Write(L"Here's the Message");
The idea is to code the EL_logger->Write() method to call the Logging App Block. Here’s how I went about it.
- Project-> References-> Add New Reference ..
- Added the following libraries:
Right click -> Properties -> Configuration Properties -> C/C++-> General. Change the value of “resolve #using references” to include “C:\Program Files\Microsoft Enterprise Library 5.0\Bin”
- Properties -> Configuration Properties -> Linker->Additional Library Directories. Add “C:\Program Files\Microsoft Enterprise Library 5.0\Bin”
- Add the following code to EL Logger.cpp
using namespace Microsoft::Practices::EnterpriseLibrary::Logging; using namespace Microsoft::Practices::EnterpriseLibrary::Common::Configuration;
- Now I have to translate the follwing step from C# to C++(step 3 in Logging Instructions Cs.pdf)
private LogWriter writer = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
So I created a private member:
- Next I create a constructor and add the line
writer = EnterpriseLibraryContainer::Current::get();
That is the part where I am stuck. Shouldn’t I get “.Current.GetInstance” here too? Can’t figure what I am doing wrong.
9) As an added measure I have also added a reference to System.Configuration and the line
10) Now coming to the configuration file:
Right Click on “Resource Files”, Add Item_> Configuration File (app.config)
I have created the configuration file as per instructions in the doc.
After compiling this is what I get:
error C2440: '=' : cannot convert from 'Microsoft::Practices::ServiceLocation::IServiceLocator ^' to 'Microsoft::Practices::EnterpriseLibrary::Logging::LogWriter ^' d:\My Docs\Visual Studio 2008\Projects\EL Logger\EL Logger\EL Logger.cpp
I know I am not doing something right. Just cant figure out what.