AssemblyInfo.vb 将 Log4NetAssembly1.exe.log4net 路径更改为用户的本地文件夹

AssemblyInfo.vb change Log4NetAssembly1.exe.log4net path to user's local folder

我的 vb.net 项目用于不同的用户,我不知道如何将 Log4NetAssembly1.exe.log4net 文件路径设置为 AssemblyInfo.vb 中用户的本地文件夹。 每个用户的 Log4NetAssembly1.exe.log4net 文件位于 C:\Users\UserName\AppData\Local\Temp\DeskApp\DeskApp\Log4NetAssembly1.exe.log4net。

我试过用下面的方法,但是不行:

<Assembly: AssemblyTitle("DeskApp")> 
<Assembly: AssemblyDescription("")> 
<Assembly: AssemblyCompany("ESRI")> 
<Assembly: AssemblyProduct("DeskApp")> 
<Assembly: AssemblyCopyright("Copyright © ESRI 2009")> 
<Assembly: AssemblyTrademark("")> 
<Assembly: log4net.Config.XMLConfigurator(ConfigFile:="${LOCALAPPDATA}\Temp\DeskApp\DeskApp\Log4NetAssembly1.exe.log4net", Watch:=True)>

我使用的是 vs 2012,在此先感谢。

编辑

我尝试将 log4net 文件放在与 AssemblyInfo.vb 相同的文件夹中,并使用:

<Assembly: log4net.Config.XMLConfigurator(ConfigFileExtension:="log4net", Watch:=True)> 

但是没有生效

如果配置文件与 .exe 位于同一文件夹中,那么您 don't need to specify an absolute path:

ConfigFile

If specified, this is the filename of the configuration file to use with the XmlConfigurator. This file path is relative to the application base directory (AppDomain.CurrentDomain.BaseDirectory).

如果配置文件位于不相关的目录中,则必须在运行时删除程序集属性并配置 log4net,否则将不会评估环境变量:

Dim filePath as String = Path.Combine(System.Environment.GetFolderPath
                                    (Environment.SpecialFolder.LocalApplicationData), 
                        "Temp\DeskApp\DeskApp\Log4NetAssembly1.exe.log4net")

Dim fileInfo As New FileInfo(filePath)

If fileInfo.Exists = False Then
    Throw New InvalidOperationException("Can't locate the log4net config file")
End If

log4net.Config.XmlConfigurator.ConfigureAndWatch(fileInfo)