views:

38

answers:

0

I think it's probably my inexperience with .net, but I think I'm going to have to give up on my plan to use NLog instead of fixing our broken proprietary logging code.

The plan was to introduce NLog then extend logging if we ever move to c#.

I've called my own simple assembly code from VC6 before (get a pointer to the managed interface, then call the functions), but can't get NLog to work.

I'm trying to use the ComInterop dll, and got a pointer to LogManager, but whenever I call InternalLogToConsole I get an exception.

It feels from my googling that this stuff just works normally, but I can't get it to, and I can't work out why. Any clues will be gratefully received.

If anyone has a sample VC6 project that might save NLog for me :-S

Here's some code that doesn't work... thx everyone.

#import "C:\Program Files\NLog\bin\net-2.0\NLog.ComInterop.tlb" no_namespace     named_guids
...

HRESULT hr = CoCreateInstance(
              CLSID_LogManager,
              NULL, 
              CLSCTX_INPROC_SERVER,
              IID_ILogManager, 
              reinterpret_cast<void**>(&pILogManager));

if (FAILED(hr))
{
  AfxMessageBox("Couldn't create LogManager!");
}
else
{
  try
  {
    pILogManager->InternalLogToConsole = VARIANT_TRUE; // this fails, system can't find the file 

    BSTR bsLogFile = SysAllocString(L"internal_log.txt");
    pILogManager->put_InternalLogFile(bsLogFile); 
    SysFreeString(bsLogFile);

    BSTR bsLogLevel = SysAllocString(L"Info");
    pILogManager->   put_InternalLogLevel(bsLogLevel); 
    SysFreeString(bsLogLevel);
  }
  catch(_com_error ex)
  {
    AfxMessageBox(ex.Description());
  }
}

...