public void Add_File_Target() { string tmpFile = Path.GetTempFileName(); ILog log = new NLogLogger("Test_Logger"); log.AddFileTarget("Test_Target", tmpFile); log.Debug("DEBUG MESSAGE"); log.Info("INFO MESSAGE"); log.Error("ERROR MESSAGE"); log.Warn("WARN MESSAGE"); log.Fatal("FATAL MESSAGE"); log.Flush(); string logContents = File.ReadAllText(tmpFile); Console.Write(logContents); Assert.True(logContents.Contains("DEBUG MESSAGE")); Assert.True(logContents.Contains("INFO MESSAGE")); Assert.True(logContents.Contains("ERROR MESSAGE")); Assert.True(logContents.Contains("WARN MESSAGE")); Assert.True(logContents.Contains("FATAL MESSAGE")); File.Delete(tmpFile); }
public ServiceRegistry() { Scan(s => { s.WithDefaultConventions(); s.TheCallingAssembly(); s.AssembliesFromApplicationBaseDirectory(skipStructureMap); s.LookForRegistries(); s.AddAllTypesOf<IService>(); }); For<ILog>().AlwaysUnique().Use(f => { ILog rv; if (null == f.ParentType) { if (null != f.BuildStack && null != f.BuildStack.Current && null != f.BuildStack.Current.ConcreteType && false == f.BuildStack.Current.ConcreteType.Name.IsNullOrWhiteSpace()) { rv = new NLogLogger(f.BuildStack.Current.ConcreteType.Name); } else { rv = new NLogLogger(defaultLoggerName); } } else { rv= new NLogLogger(f.ParentType.FullName); } return rv; }); }