public void Log(string message, LogLevel logLevel) { if (!_logLevelDeterminator.AcceptedLogLevel(logLevel)) { return; } message = $"[{DateTime.Now}]{message}"; var connString = _settingsExtractor.Get <string>("loggerConnectionString"); using (var conn = new SqlConnection(connString)) { var command = new SqlCommand("insert into Log (date,message,logLevel) values (getDate(),@message,@logLevel)"); command.Parameters.AddWithValue("@message", message); command.Parameters.AddWithValue("@type", logLevel); try { conn.Open(); command.ExecuteNonQuery(); } catch (Exception) { throw; } } }
public void Log(string message, LogLevel logLevel) { if (!_logLevelDeterminator.AcceptedLogLevel(logLevel)) { return; } message = $"[{DateTime.Now}]{message}"; var path = _settingsExtractor.Get <string>("logLocation"); var fullPath = $"{path}LogFile{DateTime.Now.ToString("yyyymmdd")}.txt"; if (!File.Exists(fullPath)) { using (var sw = File.CreateText(fullPath)) { sw.WriteLine(message); } } using (var sw = File.AppendText(fullPath)) { sw.WriteLine(message); } }