Lazy. in the new project, Nuget is used to download the log4net configuration file (that is, log4net without the version number. in detail, it indicates log4net xml), but after the configuration, log4net went on strike unexpectedly, and no error was reported. This configuration method uses an independent log4net. xml file for configuration. Loading and use: Code Var log4net_config = Path. Combine (Path. GetDirectoryName (GetType (). Assembly. Location), "log4net. xml "); XmlConfigurator. Configure (newFileInfo (log4net_config )); After checking the entire configuration, we found that the Nuget configuration file has some missing information: The first is the file name, log4net. xml is not so easy to use, because log4net itself will also generate a file with the same name. if you are stubborn to use xml files, you need to work with the second point, make sure that the file in the output directory is indeed a configuration file. you are advised to change it to log4net. config is more appropriate; The second is the file attribute in the project. to copy the file to the output directory, you must set it to always copy or newer copy. the generation operation should not be none. select the content; After modifying the configuration file according to the preceding figure, log4net will survive after loading with the following code. Code Var log4net_config = Path. Combine (Path. GetDirectoryName (GetType (). Assembly. Location), "log4net. config"); // here is diff. XmlConfigurator. Configure (newFileInfo (log4net_config )); For simplicity, you can also use the following in AssemblyInfo. cs: Code // Note: it is added to the AssemblyInfo. cs file. [Assembly: log4net. Config. XmlConfigurator (ConfigFile = "log4net. config", Watch = true)]; Well, log4net can play with us again. Receive free Brothers IT education original linux O & M engineers video/detailed linux tutorial, details consulting official website Customer Service: http://www.lampbrother.net/linux/ Learn PHP, Linux, HTML5, UI, Android and other video tutorials (courseware + Notes + video )! Contact Q2430675018
|