예제 #1
0
        public void Log(LogLevel logLevel, string message, params object[] propertyValues)
        {
            var level = TranslateLogLevel(logLevel);

            lock (LogLock.Lock)
            {
                _logger.Write(level, message, propertyValues);
            }
        }
예제 #2
0
 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);
     }
 }
예제 #3
0
        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);
 }
예제 #5
0
                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);
     }
 }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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);
                                }
                        }
                    }
                }
        }
예제 #9
0
 void WriteSerilog(LogEventLevel level, object obj)
 {
     if (obj is string)
     {
         _logger.Write(level, "{Message:l}", obj);
     }
     else
     {
         _logger.Write(level, ObjectLogTemplate, obj);
     }
 }
예제 #10
0
        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);
             }
         }
     }
 }
예제 #12
0
        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);
            }
        }
예제 #13
0
 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);
예제 #15
0
파일: StarsLogger.cs 프로젝트: m12e/Stars
        public virtual void Write(string message, LogLevel logLevel)
        {
            var mappedLogLevel = logLevel.ToSerilogLevel();

            _logger.Write(mappedLogLevel, message);
        }
예제 #16
0
 public void Error(string message, Exception ex = null)
 {
     _logger.Write(LogEventLevel.Error, "Message: {1},{0} Exception: {2}", Environment.NewLine, message, ex);
 }
예제 #17
0
 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);
 }
예제 #19
0
 public void Write(string message, LogLevel level)
 {
     _logger.Write((LogEventLevel)level, message);
 }