示例#1
0
        public static J4JLoggerConfiguration AddTwilio(this J4JLoggerConfiguration loggerConfig,
                                                       TwilioConfiguration configValues,
                                                       LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose,
                                                       string?outputTemplate = null)
        {
            if (!configValues.IsValid)
            {
                throw new ArgumentException("Twilio configuration values are invalid");
            }

            var sink = new TwilioSink(configValues.FromNumber !,
                                      configValues.Recipients !,
                                      outputTemplate ?? loggerConfig.GetOutputTemplate());

            try
            {
                TwilioClient.Init(configValues.AccountSID !, configValues.AccountToken !);
                sink.IsConfigured = true;

                loggerConfig.AddSmsSink(sink, restrictedToMinimumLevel);
            }
            catch
            {
                sink.IsConfigured = false;
            }

            return(loggerConfig);
        }
示例#2
0
        //public static LoggerConfiguration NetEvent(
        //    this LoggerSinkConfiguration loggerConfig,
        //    out NetEventSink sink,
        //    string outputTemplate = NetEventSink.DefaultTemplate,
        //    LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose
        //    )
        //{
        //    sink = new NetEventSink( outputTemplate );

        //    return loggerConfig.Sink( sink, restrictedToMinimumLevel );
        //}

        public static LoggerConfiguration NetEvent(this J4JLoggerConfiguration loggerConfig,
                                                   string outputTemplate = NetEventSink.DefaultTemplate,
                                                   LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose)
        {
            var sink = new NetEventSink(outputTemplate);

            loggerConfig.NetEventSink = sink;

            return(loggerConfig.SerilogConfiguration
                   .WriteTo
                   .Sink(sink, restrictedToMinimumLevel));
        }