我有一个带有log4net的控制台应用程序,我想从代码中添加日志文件名.(我稍后使用线程)
class Program
{
static void Main(string[] args)
{
{
log4net.GlobalContext.Properties["fname"] = "aaaa";
log4net.Config.XmlConfigurator.Configure();
}
}
}
<appender name="default" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="d:\\TEMP\\default_%property{fname}.log"/>
...
</appender>
Run Code Online (Sandbox Code Playgroud)
我得到(null).
谢谢你的帮助.
我尝试重新抛出异常,但它不起作用.我在Visual Studio中得到'Exception is unhandled'错误.
public KeyValueConfigurationCollection getMyAppSetting()
{
Configuration config;
ConfigurationFileMap configFile;
try
{
configFile = new ConfigurationFileMap(ConfigurationManager.OpenMachineConfiguration().FilePath);
config = ConfigurationManager.OpenMappedMachineConfiguration(configFile);
AppSettingsSection MyAppSettingSection = (AppSettingsSection)config.GetSection("xxx/appSettings");
MyAppSettingSection.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToRoamingUser;
return MyAppSettingSection.Settings;
}
catch (Exception ex)
{
logger.Fatal("...");
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
此方法属于类库,我从控制台应用程序调用它.请帮我.
谢谢.
我尝试将我的对象存储在asmx Web服务中的会话中
user = new MyUser(UserName);
Session["user"] = user;
Run Code Online (Sandbox Code Playgroud)
并从页面加载部分的主页读取,但我得到null
user = (MyUser)Session["user"];
Run Code Online (Sandbox Code Playgroud)
当我尝试使用简单的字符串而不是MyUser
对象时它可以工作
任何的想法?
谢谢.