/// <summary> /// Public function to log either a text message or an exception, or both. /// </summary> /// <param name="message">The message to log.</param> /// <param name="exception">The exception to log.</param> /// <param name="callingMethod">The method that made the request to log the error.</param> /// <returns>Returns the name of the file the log was saved in.</returns> public string Log(string message, Exception exception = null, IClock clock = null, [CallerMemberName] string callingMethod = "") { try { if (clock == null) { clock = new DefaultClock(); } string filename = GetLogFilename(clock); if (string.IsNullOrEmpty(filename)) { return(null); } string output = ComposeOutput(callingMethod, message, exception, clock); if (output == null) { return(null); } File.AppendAllText(filename, output); return(filename); } catch { return(null); } }
public static ILoggingBuilder Install(ILoggingBuilder loggingBuilder) { var clock = new DefaultClock(); var provider = new MemoryLogger(clock); loggingBuilder.Services.AddSingleton(provider); return(loggingBuilder.AddProvider(provider)); }