我如何在.NET中启用程序集绑定失败日志记录(融合)?


当前回答

您可以以管理员身份运行此Powershell脚本来启用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

这个要禁用:

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

其他回答

我通常使用Fusion日志查看器(从Visual Studio命令提示符或从开始菜单中的Fusion日志查看器中的Fuslogvw.exe) -我的标准设置是:

以管理员身份打开Fusion Log Viewer 点击设置 选中“启用自定义日志路径”复选框 输入要写入日志的位置,例如c:\FusionLogs(注意:请确保您已经在文件系统中创建了此文件夹)。 确保打开了正确的日志级别(我有时只是选择“日志全部绑定到磁盘”,只是为了确保事情正常工作) 单击OK 将日志位置选项设置为自定义

一旦你完成了,记得关闭登录!

(我刚刚就一个类似的问题发表了这篇文章——我认为这也与此相关。)

您也可以通过ETW/xperf通过GUID 763FD754-7086-4DFE-95EB-C01A46FAF4CA和FusionKeyword关键字(0x4)打开dotnetruntimeprivate提供者(Microsoft-Windows-DotNETRuntimePrivate)来激活Fusion日志。

@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

当你现在在PerfView中打开ETL文件并在事件表下查看时,你可以找到Fusion数据:

在我的例子中,帮助键入小写的磁盘名称

错误- C:\someFolder

正确- c:\someFolder

设置以下注册表值:

(微软HKEY_LOCAL_MACHINE \ SOFTWARE \ \融合!EnableLog] (DWORD)到1

若要禁用,请设置为0或删除该值。

[edit]:将以下文本保存为文件,如“FusionEnableLog”。注册, Windows注册表编辑器格式:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
"EnableLog"=dword:00000001

然后从windows资源管理器运行该文件,并忽略有关可能损坏的警告。

融合日志设置查看器更改脚本是做到这一点的最好方法。

在ASP。NET中,有时要使它正确工作是很棘手的。这个脚本工作得很好,也被列入了Scott Hanselman的Power Tool列表。我个人已经使用它很多年了,它从来没有让我失望过。