public async Task <ActionResult> GetExtendForm(string keyword) { string filePath = GlobalContext.HostingEnvironment.WebRootPath + $@"/form/"; DirectoryInfo root = new DirectoryInfo(filePath); List <AppLogEntity> list = new List <AppLogEntity>(); foreach (FileInfo f in root.GetFiles()) { AppLogEntity app = new AppLogEntity(); app.FileName = f.Name.Remove(f.Name.Length - 5, 5);; list.Add(app); } return(Content(list.ToJson())); }
/// <summary> /// 获得指定路径下所有文件名 /// </summary> /// <param name="sw">列表</param> /// <param name="path">文件夹路径</param> public static void getDirectory(List <AppLogEntity> sw, string path) { DirectoryInfo root = new DirectoryInfo(path); foreach (FileInfo f in root.GetFiles()) { AppLogEntity app = new AppLogEntity(); app.FileName = f.Name; sw.Add(app); } foreach (DirectoryInfo d in root.GetDirectories()) { getDirectory(sw, d.FullName); } }
/// <summary> /// Creates a model based on the given domain entity. /// </summary> /// <param name="entity">The domain entity.</param> /// <returns>The domain entity as a model.</returns> public static AppLogModel Create(AppLogEntity entity) { if (entity == null) { return(null); } var model = new AppLogModel { Timestamp = entity.Timestamp, Message = entity.Message, Level = entity.Level, Exception = entity.Exception, EventId = entity.EventId, SourceContext = entity.SourceContext }; return(model); }
private void AssertLog(string logLevel) { var logs = fixture.GetLogs(); Assert.NotNull(logs); Assert.True(logs.Count == 1); AppLogEntity log = logs.FirstOrDefault(); Assert.Equal("Test App", log.ApplicationId); Assert.Equal($"test {logLevel}", log.Message); Assert.Equal(logLevel, log.Level); Assert.Equal($"test {logLevel}", log.MessageTemplate); Assert.NotEmpty(log.Properties); Assert.Contains("MachineName", log.Properties); Assert.Contains("ProcessName", log.Properties); Assert.Contains("ProcessId", log.Properties); Assert.Contains("ThreadId", log.Properties); Assert.Contains("EnvironmentUserName", log.Properties); }