static SerilogBenchmark()
        {
            var logInjectionSettings = new TracerSettings
            {
                StartupDiagnosticLogEnabled = false,
                LogsInjectionEnabled        = true,
                Environment    = "env",
                ServiceVersion = "version"
            };

            LogInjectionTracer = new Tracer(logInjectionSettings, new DummyAgentWriter(), null, null, null);
            Tracer.UnsafeSetTracerInstance(LogInjectionTracer);

            var formatter = new MessageTemplateTextFormatter("{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}{Properties}{NewLine}", null);

            Logger = new LoggerConfiguration()
                     // Add Enrich.FromLogContext to emit Datadog properties
                     .Enrich.FromLogContext()
                     .WriteTo.Sink(new NullSink(formatter))
                     .CreateLogger();

            LogEvent = new LogEvent(
                DateTimeOffset.Now,
                LogEventLevel.Information,
                exception: null,
                new MessageTemplate("Hello", Enumerable.Empty <MessageTemplateToken>()),
                properties: Enumerable.Empty <LogEventProperty>());
        }
Beispiel #2
0
        static SerilogBenchmark()
        {
            LogProvider.SetCurrentLogProvider(new CustomSerilogLogProvider());

            var logInjectionSettings = new TracerSettings
            {
                StartupDiagnosticLogEnabled = false,
                LogsInjectionEnabled        = true,
                Environment    = "env",
                ServiceVersion = "version"
            };

            LogInjectionTracer = new Tracer(logInjectionSettings, null, new DummyAgentWriter(), null, null, null);
            Tracer.Instance    = LogInjectionTracer;

            var baselineSettings = new TracerSettings
            {
                StartupDiagnosticLogEnabled = false,
                LogsInjectionEnabled        = false,
                Environment    = "env",
                ServiceVersion = "version"
            };

            BaselineTracer = new Tracer(baselineSettings, null, new DummyAgentWriter(), null, null, null);
            var formatter = new MessageTemplateTextFormatter("{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}{Properties}{NewLine}", null);

            Logger = new LoggerConfiguration()
                     // Add Enrich.FromLogContext to emit Datadog properties
                     .Enrich.FromLogContext()
                     .WriteTo.Sink(new NullSink(formatter))
                     .CreateLogger();
        }
Beispiel #3
0
 internal Logger(string prefix, bool isDebug, string pathName = null)
 {
     _prefix = prefix;
     _path   = Path.Combine(Bridge.LogPath, pathName ?? prefix);
     Directory.CreateDirectory(_path);
     _isDebug        = isDebug;
     _internalLogger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Console().WriteTo.Sink(new EventLogSink(this)).CreateLogger();
 }
Beispiel #4
0
        private static void PruebaTraceService(Serilog.Core.Logger log)
        {
            var traceService = new TraceService {
                Logger = log
            };

            traceService.Trace(LogEventLevel.Information, "Hola", "Ha pasado esto", "General");
            traceService.Trace(LogEventLevel.Error, "Hola", "Ha petao", "General");
        }
Beispiel #5
0
        private static void Pruebasbasicas(Serilog.Core.Logger log)
        {
            log.Write(LogEventLevel.Information, "Que pasa troncu Hola Mostru");

            //log.Write(LogEventLevel.Error, "HA PETAO {MachineName}", new { MachineName = Environment.MachineName });
            //log.Write(LogEventLevel.Error, "HA PETAO2 ", new { MachineName = Environment.MachineName });
            log.Write(LogEventLevel.Error, "HA PETAO3", Environment.MachineName);

            //log.Write(LogEventLevel.Error,"")
        }
Beispiel #6
0
 private static void Initialize()
 {
     _instance = new LoggerConfiguration()
                 .MinimumLevel.Information()
                 .Enrich.FromLogContext()
                 .Enrich.WithMachineName()
                 .Enrich.WithThreadId()
                 .WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.ffffff} | {Level:u} | {MachineName} | {ThreadId} | {Scope} >>> {Message}{NewLine}{Exception}", theme: AnsiConsoleTheme.Code)
                 .CreateLogger();
 }
        public static void ConfigureStandardLogger(ILoggerFactory factory)
        {
            var logOutputTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff } {Level:u3} TH:{ThreadId,3}] {SourceContext} - {Message}{NewLine}{Exception}";
            var consoleOutput     = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff } {Level:u3} TH:{ThreadId,2}] {Message}{NewLine}{Exception}";

            var cfg = new LoggerConfiguration()
                      .MinimumLevel.ControlledBy(levelSwitch)
                      .Enrich.WithThreadId()
                      .Enrich.WithThreadName()
                      .WriteTo.Console(outputTemplate: consoleOutput);

            foreach (var file in loggingPaths)
            {
                cfg.WriteTo.Async(a => a.File(file, outputTemplate: logOutputTemplate, rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: false, shared: true));
            }
            serilogLogger = cfg.CreateLogger();

            factory.AddSerilog(serilogLogger);
        }
Beispiel #8
0
        internal static ILoggerFactory GetLoggerFactory(LogEventLevel logEventLevel, Func <LoggerSinkConfiguration, LoggerConfiguration> loggerSink)
        {
            var levelSwitch = new LoggingLevelSwitch
            {
                MinimumLevel = logEventLevel
            };

            LoggerSinkConfiguration loggerSinkConfiguration = new LoggerConfiguration()
                                                              .MinimumLevel.ControlledBy(levelSwitch)
                                                              .Enrich.FromLogContext()
                                                              .Enrich.With(SeverityEnricher.Instance)
                                                              .WriteTo;

            Serilog.Core.Logger loggerConfig = loggerSink(loggerSinkConfiguration).CreateLogger();

            ILoggerFactory factory = new LoggerFactory()
                                     .AddSerilog(loggerConfig);

            return(factory);
        }
 public OpcUaStreaming(Serilog.Core.Logger logIn)
 {
     log = logIn;
 }
        /// <summary>
        /// Create a new Log instance with default context with a failure sink.
        /// </summary>
        /// <param name="environment">The environment must be provided. This determines the ELK index, e.g. alog-local or alog-production.</param>
        /// <param name="config">Configuration for minimum log level and Elasticsearch connection details.</param>
        /// <param name="failureSink">Serilog failure sink. Pass null if not used.</param>
        /// <param name="failureCallback">Serilog failure callback. Pass null if not used.</param>
        /// <param name="enrichers">Serilog enrichers. If null, the default LogEnricher is used.</param>
        public Log(ElasticConfig config, LogLevel level, Func <string> createIndexName, ILogEventSink failureSink, Action <LogEvent> failureCallback, ILogEventEnricher[] enrichers)
        {
            _index           = null == createIndexName ? "default" : createIndexName();
            _config          = config;
            _level           = level;
            _enrichers       = enrichers;
            _failureSink     = failureSink;
            _failureCallback = failureCallback;

            var elasticOptions = new ElasticsearchSinkOptions(new Uri(config.Url))
            {
                CustomFormatter      = new LogExceptionFormatter(),
                MinimumLogEventLevel = LogEventLevel.Verbose,
                AutoRegisterTemplate = false,
                IndexDecider         = (logEventProxy, dateTimeOffset) => _index,
                OverwriteTemplate    = false,
                FailureCallback      = null != _failureCallback
                        ? _failureCallback
                        : (e) =>
                {
                    Console.WriteLine("Unable to submit event " + e.MessageTemplate);
                },
                EmitEventFailure = null != _failureSink
                        ? EmitEventFailureHandling.WriteToSelfLog |
                                   EmitEventFailureHandling.WriteToFailureSink |
                                   EmitEventFailureHandling.RaiseCallback
                        : EmitEventFailureHandling.WriteToSelfLog |
                                   EmitEventFailureHandling.RaiseCallback,
                FailureSink = _failureSink
            };

            if (!string.IsNullOrWhiteSpace(_config.ElasticUser))
            {
                elasticOptions.ModifyConnectionSettings = (connConfig) => connConfig.BasicAuthentication(config.ElasticUser, config.ElasticPassword);
            }

            Serilog.Debugging.SelfLog.Enable(msg =>
            {
                Console.WriteLine(msg);
            });

            var logConfig = new LoggerConfiguration()
                            .WriteTo.Console()
                            .WriteTo.Elasticsearch(elasticOptions);

            if (null == enrichers || enrichers.Length == 0)
            {
                enrichers = new[] { new LogEnricher() };
            }
            logConfig.Enrich.With(enrichers);

            switch (_level)
            {
            case LogLevel.Trace:
                logConfig.MinimumLevel.Verbose();
                break;

            case LogLevel.Debug:
                logConfig.MinimumLevel.Debug();
                break;

            case LogLevel.Info:
                logConfig.MinimumLevel.Information();
                break;

            case LogLevel.Warn:
                logConfig.MinimumLevel.Warning();
                break;

            case LogLevel.Error:
                logConfig.MinimumLevel.Error();
                break;

            default:
                logConfig.MinimumLevel.Fatal();
                break;
            }

            _logger = logConfig.CreateLogger();
            var ctx = new LogContext();
        }
Beispiel #11
0
 public Sync(Serilog.Core.Logger pLog)
 {
     this.log = pLog;
 }
Beispiel #12
0
 public MainPlayer()
 {
     _logger = new Serilog.LoggerConfiguration().WriteTo.UnityConsole().CreateLogger();
 }