public void Log(LogLevel logLevel, string message, params object[] propertyValues) { var level = TranslateLogLevel(logLevel); lock (LogLock.Lock) { _logger.Write(level, message, propertyValues); } }
private void Write(LogLevel level, Exception exception, object message) { if (message is string) { _logger.Write(level.ToSerilogEventLevel(), exception, "{Message:l}", message.ToString()); } else { _logger.Write(level.ToSerilogEventLevel(), exception, "{@Message}", message); } }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { var level = ConvertLevel(logLevel); if (!_logger.IsEnabled(level)) { return; } string messageFormat; List <object> props; ParseState(state as IEnumerable <KeyValuePair <string, object> >, out messageFormat, out props); if (messageFormat == null) { messageFormat = formatter(state, exception); } IEnumerable <LogEventProperty> boundProps; MessageTemplate messageTemplate; _logger.BindMessageTemplate(messageFormat, props.ToArray(), out messageTemplate, out boundProps); var properties = new List <LogEventProperty> { new LogEventProperty("EventId", new ScalarValue(eventId.Id)), new LogEventProperty("EventName", new ScalarValue(eventId.Name)), }; properties.AddRange(boundProps); var logEvent = new LogEvent(DateTimeOffset.Now, level, exception, messageTemplate, properties); _logger.Write(logEvent); }
internal void TraceWriteLine(LogEventLevel level, string message, Dictionary <string, object> properties = null) { if (properties != null) { foreach (var item in properties) { workItemLog = workItemLog.ForContext(item.Key, item.Value); } } workItemLog.Write(level, workItemLogTeamplate + message); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (logLevel == LogLevel.None || !IsEnabled(logLevel)) { return; } var serilogLevel = levelMapping[logLevel]; var logString = formatter(state, exception); logger.Write(LogEventLevel.Debug, exception, logString); }
public void Write(LogEvent logEvent) { try { _logger.Write(logEvent); } catch (Exception ex) { Console.WriteLine($"!!!!!!! [ERROR]Cannot write to Serilog.ILogger. Exception: {ex}"); LogToConsole(logEvent); } }
public static void log(object msg, Serilog.Events.LogEventLevel level = Serilog.Events.LogEventLevel.Information) { string s = System.Threading.Thread.CurrentThread.ManagedThreadId + " " + msg.ToString(); if (_logger is not null) { _logger.Write(level, s); } else { Console.WriteLine(System.DateTime.Now.ToString("HH-mm-ss-fff") + " " + s); } }
public void BuildPackage(string basePath, IList <string> includes, ManifestMetadata metadata, string outFolder, bool overwrite, bool verboseInfo) { var filename = metadata.Id + "." + metadata.Version + ".zip"; var output = fileSystem.GetFullPath(Path.Combine(outFolder, filename)); if (fileSystem.FileExists(output) && !overwrite) { throw new CommandException("The package file already exists and --overwrite was not specified"); } log.Information("Saving {Filename} to {OutFolder}...", filename, outFolder); fileSystem.EnsureDirectoryExists(outFolder); var logLevel = verboseInfo ? LogEventLevel.Verbose : LogEventLevel.Debug; var basePathLength = fileSystem.GetFullPath(basePath).Length; using (var stream = fileSystem.OpenFile(output, FileAccess.Write)) using (var archive = new ZipArchive(stream, ZipArchiveMode.Create)) { foreach (var pattern in includes) { log.Debug("Adding files from {Path} matching pattern {Pattern}", basePath, pattern); foreach (var file in PathResolver.PerformWildcardSearch(basePath, pattern)) { var fullFilePath = fileSystem.GetFullPath(file); if (string.Equals(fullFilePath, output, StringComparison.CurrentCultureIgnoreCase)) { continue; } var relativePath = UseCrossPlatformDirectorySeparator( fullFilePath.Substring(basePathLength).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); log.Write(logLevel, "Added file: {relativePath}"); var entry = archive.CreateEntry(relativePath, CompressionLevel.Optimal); entry.LastWriteTime = new DateTimeOffset(new FileInfo(file).LastWriteTime); using (var entryStream = entry.Open()) using (var sourceStream = File.OpenRead(file)) { sourceStream.CopyTo(entryStream); } } } } }
void WriteSerilog(LogEventLevel level, object obj) { if (obj is string) { _logger.Write(level, "{Message:l}", obj); } else { _logger.Write(level, ObjectLogTemplate, obj); } }
static void Log(HttpContext httpContext, Stopwatch sw) { sw.Stop(); int? statusCode = httpContext.Response?.StatusCode; LogEventLevel level = statusCode > 499 ? LogEventLevel.Error : statusCode > 399 ? LogEventLevel.Warning : LogEventLevel.Information; _log.Write( level, MessageTemplate, httpContext.Request.Protocol, httpContext.Request.Method, httpContext.Request.Scheme, httpContext.Request.Host, httpContext.Request.Path, httpContext.Request.QueryString, statusCode, sw.Elapsed.TotalMilliseconds); }
private void ReadPipeForever() { using (var _srPipe = new StreamReader(_pipeMessages)) { while (_pipeMessages.IsConnected) { var txt = _srPipe.ReadLine(); if (txt != null) { var logEvent = Newtonsoft.Json.JsonConvert.DeserializeObject <SimplifiedLogEvent>(txt); _logger.Write(logEvent.Level, logEvent.Exception, logEvent.MessageTemplate, logEvent.Properties); } else { Thread.Sleep(10); } } } }
public void Log(LogLevel level, string message, object[] args, IFormatProvider formatProvider, string category, string nativeErrorInfo, Exception ex) { if (level >= minLogLevel) { var text = message; if (args != null && args.Length > 0) { text = string.Format(formatProvider ?? CultureInfo.InvariantCulture, message, args); } logger.Write(ToLevel(level), ex, text); } }
public void Write(LogLevel level, Exception exception, string messageTemplate, params object[] propertyValues) { _logger.Write(level.AsSerilogLevel(), exception, messageTemplate, propertyValues); }
public void Log(LogLevel level, string message, params object[] args) => _serilogLogger.Write(GetSerilogLevel(level), message, args);
public virtual void Write(string message, LogLevel logLevel) { var mappedLogLevel = logLevel.ToSerilogLevel(); _logger.Write(mappedLogLevel, message); }
public void Error(string message, Exception ex = null) { _logger.Write(LogEventLevel.Error, "Message: {1},{0} Exception: {2}", Environment.NewLine, message, ex); }
public void LogFatal(string template, params object[] parameters) { _logger.Write(LogEventLevel.Fatal, template, parameters); }
public void Log(LogEntry entry) { _logger.Write((LogEventLevel)entry.Severity, entry.Exception, entry.Message); }
public void Write(string message, LogLevel level) { _logger.Write((LogEventLevel)level, message); }