Wix C# Custom Action Logging Not Working

2019-01-11 23:15发布

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 action 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>

标签: wix
2条回答
Explosion°爆炸
2楼-- · 2019-01-11 23:39

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.

查看更多
来,给爷笑一个
3楼-- · 2019-01-11 23:58

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)
{
    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.

查看更多
登录 后发表回答