How to enable assembly bind failure logging (Fusion) in .NET

后端 未结 13 2894
难免孤独
难免孤独 2020-11-21 04:50

How do I enable assembly bind failure logging (Fusion) in .NET?

相关标签:
13条回答
  • 2020-11-21 05:22

    Add the following values to

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion
    Add:
    DWORD ForceLog set value to 1
    DWORD LogFailures set value to 1
    DWORD LogResourceBinds set value to 1
    DWORD EnableLog set value to 1
    String LogPath set value to folder for logs (e.g. C:\FusionLog\)
    

    Make sure you include the backslash after the folder name and that the Folder exists.

    You need to restart the program that you're running to force it to read those registry settings.

    By the way, don't forget to turn off fusion logging when not needed.

    0 讨论(0)
  • 2020-11-21 05:22

    Set the following registry value:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion!EnableLog] (DWORD) to 1

    To disable, set to 0 or delete the value.

    [edit ]:Save the following text to a file, e.g FusionEnableLog.reg, in Windows Registry Editor Format:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
    "EnableLog"=dword:00000001
    

    Then run the file from windows explorer and ignore the warning about possible damage.

    0 讨论(0)
  • 2020-11-21 05:23

    You can run this Powershell script as administrator to enable FL:

    Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name ForceLog         -Value 1               -Type DWord
    Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogFailures      -Value 1               -Type DWord
    Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogResourceBinds -Value 1               -Type DWord
    Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogPath          -Value 'C:\FusionLog\' -Type String
    mkdir C:\FusionLog -Force
    

    and this one to disable:

    Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name ForceLog
    Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogFailures
    Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogResourceBinds
    Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogPath
    
    0 讨论(0)
  • 2020-11-21 05:27

    Instead of using a ugly log file, you can also activate Fusion log via ETW/xperf by turning on the DotnetRuntime Private provider (Microsoft-Windows-DotNETRuntimePrivate) with GUID 763FD754-7086-4DFE-95EB-C01A46FAF4CA and the FusionKeyword keyword (0x4) on.

    @echo off
    echo Press a key when ready to start...
    pause
    echo .
    echo ...Capturing...
    echo .
    
    "C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -on PROC_THREAD+LOADER+PROFILE -stackwalk Profile -buffersize 1024 -MaxFile 2048 -FileMode Circular -f Kernel.etl
    "C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -start ClrSession -on Microsoft-Windows-DotNETRuntime:0x8118:0x5:'stack'+763FD754-7086-4DFE-95EB-C01A46FAF4CA:0x4:0x5 -f clr.etl -buffersize 1024
    
    echo Press a key when you want to stop...
    pause
    pause
    echo .
    echo ...Stopping...
    echo .
    
    "C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -start ClrRundownSession -on Microsoft-Windows-DotNETRuntime:0x8118:0x5:'stack'+Microsoft-Windows-DotNETRuntimeRundown:0x118:0x5:'stack' -f clr_DCend.etl -buffersize 1024 
    
    timeout /t 15
    
    set XPERF_CreateNGenPdbs=1
    
    "C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -stop ClrSession ClrRundownSession 
    "C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -stop
    "C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -merge kernel.etl clr.etl clr_DCend.etl Result.etl -compress
    del kernel.etl
    del clr.etl
    del clr_DCend.etl
    

    When you now open the ETL file in PerfView and look under the Events table, you can find the Fusion data:

    0 讨论(0)
  • 2020-11-21 05:33

    For those who are a bit lazy, I recommend running this as a bat file for when ever you want to enable it:

    reg add "HKLM\Software\Microsoft\Fusion" /v EnableLog /t REG_DWORD /d 1 /f
    reg add "HKLM\Software\Microsoft\Fusion" /v ForceLog /t REG_DWORD /d 1 /f
    reg add "HKLM\Software\Microsoft\Fusion" /v LogFailures /t REG_DWORD /d 1 /f
    reg add "HKLM\Software\Microsoft\Fusion" /v LogResourceBinds /t REG_DWORD /d 1 /f
    reg add "HKLM\Software\Microsoft\Fusion" /v LogPath /t REG_SZ /d C:\FusionLog\
    
    if not exist "C:\FusionLog\" mkdir C:\FusionLog
    
    0 讨论(0)
  • 2020-11-21 05:34

    I usually use the Fusion Log Viewer (Fuslogvw.exe from a Visual Studio command prompt or Fusion Log Viewer from the start menu) - my standard setup is:

    • Open Fusion Log Viewer as administrator
    • Click settings
    • Check the Enable custom log path checkbox
    • Enter the location you want logs to get written to, for example, c:\FusionLogs (Important: make sure that you have actually created this folder in the file system.)
    • Make sure that the right level of logging is on (I sometimes just select Log all binds to disk just to make sure things are working right)
    • Click OK
    • Set the log location option to Custom

    Remember to turn of logging off once you're done!

    (I just posted this on a similar question - I think it's relevant here too.)

    0 讨论(0)
提交回复
热议问题