开发者

Wix C# Custom Action Logging Not Working

开发者 https://www.devze.com 2023-01-11 14:05 出处:网络
I am trying to log from my C# Custom Action using session.Log( \"Hello World!\" ); This does not show up in my log file when executing my msi as follows:

I am trying to log from my C# Custom Action using session.Log( "Hello World!" ); This does not show up in my log file when executing my msi as follows:

msiexec /i myMsi.msi /lvx myLog.log

My custom act开发者_如何学Pythonion works fine, my only problem is I do not get my logging info. The log shows my CA is getting called, just not the info from my session.Log() call.

I am using Wix 3.5, .Net 4, VS 2010, and 64-bit Windows 7. I am calling my action as follows.

<Control Id="TestConnection" Type="PushButton" X="21" Y="177" Width="100" Height="17" Text="Test Connection">
  <Publish Event="DoAction" Value="TestConnection">1</Publish>
</Control>


Per the docs on DoAction ControlEvent, MsiProcessMessage (the API behind session.Log) cannot be used from a ControlEvent. This prevents your message from showing up in the log. If you need to log some information from a ControlEvent (especially for debugging), your best bet is a hack like changing a property's value to contain your desired log information.


I got around this by using the unmanaged OutputDebugString:

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern void OutputDebugString(string message);

public bool IsDebugLogging { get; set; }

public void Log(string message)
{
    // Uncomment if you have access to the Session object passed into your custom action.
    // Session.Log(message);
    if (IsDebugLogging)
    {
        OutputDebugString(message);
    }
}

In my custom action, I set IsDebugLogging = true to enable OutputDebugString logging. This output can be viewed using Sysinternal's DebugView.

0

精彩评论

暂无评论...
验证码 换一张
取 消