public IAppender GetAppender(string appenderType, string layoutType, string levelStr) { Level level = MessageParameters.ParseLevel(levelStr); ILayout layout = this.layoutFactory.GetLayout(layoutType); Assembly assembly = Assembly.GetExecutingAssembly(); Type typeToCreate = assembly .GetTypes() .FirstOrDefault(t => t.Name == appenderType); if (typeToCreate == null) { throw new InvalidLayoutTypeException(); } List <object> args = new List <object>() { layout, level }; if (appenderType == "FileAppender") { IFile file = new LogFile(); args.Add(file); } IAppender appender = (IAppender)Activator.CreateInstance(typeToCreate, args.ToArray()); //WITHOUT REFLECTION: //Level level = MessageParameters.ParseLevel(levelStr); //ILayout layout = this.layoutFactory.GetLayout(layoutType); //IAppender appender; //if (appenderType == "ConsoleAppender") //{ // appender = new ConsoleAppender(layout, level); //} //else if (appenderType == "FileAppender") //{ // IFile file = new LogFile(); // appender = new FileAppender(layout, level, file); //} //else //{ // throw new InvalidAppenderTypeException(); //} return(appender); }
public IError GetError(string dateString, string levelStr, string message) { Level level = MessageParameters.ParseLevel(levelStr); DateTime dateTime; try { dateTime = DateTime.ParseExact(dateString, MessageParameters.dateFormat, CultureInfo.InvariantCulture); } catch { throw new InvalidDateFormatException(); } return(new Error(dateTime, message, level)); }