项目结构
引入依赖
log4net.dll
配置程序集
在AssemblyInfo.cs的最后一行添加以下内容
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
配置app.config
测试
class Program{ public static readonly ILog log = LogManager.GetLogger(typeof(Program)); static void Main(string[] args) { log.Info("哈哈"); try { int zero = 0; var a = 1 / zero; } catch (Exception ex) { log.Error("呜呜", ex); } }}