public ConcurrentDatabaseLogger(DatabaseLoggerSettings Settings, IDatabase Database) : base(Settings)
 {
     if (!Settings.Connection.IsNullOrEmpty() && (Settings.Connection.IndexOf("Connection Timeout", StringComparison.CurrentCultureIgnoreCase) < 0))
     {
         // Append timeout to connection string.
         _connection = $"{Settings.Connection};Connection Timeout={_connectionTimeoutSec}";
     }
     else _connection = Settings.Connection;
     _database = Database;
     try
     {
         _hostId = RegisterHost(Environment.MachineName);
     }
     catch (Exception exception)
     {
         var newException = new Exception("Failed to register logging host.  Logging disabled.", exception);
         WriteCriticalError(newException);
         return;
     }
     try
     {
         _processId = RegisterProcess(Settings.AppName, Settings.ProcessName);
     }
     catch (Exception exception)
     {
         var newException = new Exception("Failed to register logging process.  Logging disabled.", exception);
         WriteCriticalError(newException);
     }
 }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.AddMvc();
            services.Configure <Microsoft.AspNetCore.Http.Features.FormOptions>(x =>
            {
                x.ValueLengthLimit         = int.MaxValue;
                x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart
            });
            AddApiClientAuthentication(services);

            var connection = Microsoft.Extensions.Configuration.ConfigurationExtensions.GetConnectionString(this.Configuration, "M3PactConnection");

            DatabaseLoggerSettings dataBaseLoggerSettings = new DatabaseLoggerSettings
            {
                DbSettings = new DbSettings
                {
                    Columns = new List <Column> {
                        new Column {
                            MapTo = "Time", Name = "Time", Type = "DATETIME"
                        },
                        new Column {
                            MapTo = "LogLevel", Name = "LogLevel", Type = "TEXT"
                        },
                        new Column {
                            MapTo = "Message", Name = "Message", Type = "TEXT"
                        },
                        new Column {
                            MapTo = "Exception", Name = "Exception", Type = "TEXT"
                        },
                        new Column {
                            MapTo = "StackTrace", Name = "StackTrace", Type = "TEXT"
                        },
                    },
                    ConnectionString = connection,
                    TableName        = "Log"
                },
                LogLevel = LogLevel.Error
            };

            services.AddDbContext <M3PactContext>(options => options.UseSqlServer(connection));
            services.AddLogger(
                new CompoisteLoggerSettings(
                    new List <LoggerSettings> {
                dataBaseLoggerSettings
            }));
            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.RegisterServices();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version        = "v1",
                    Title          = "M3Pact API",
                    Description    = "M3Pact API for Client,Deposits and Admins",
                    TermsOfService = "None"
                });
            });
        }
Example #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services
            services.AddCors();
            services.AddMvc();

            // Add scheduled tasks & scheduler
            services.AddSingleton <IScheduledTask, KPIAlertTask>();
            services.AddSingleton <IConfiguration>(Configuration);
            services.AddScheduler((sender, args) =>
            {
                Console.Write(args.Exception.Message);
                args.SetObserved();
            });

            var connection = Microsoft.Extensions.Configuration.ConfigurationExtensions.GetConnectionString(this.Configuration, "M3PactConnection");

            services.AddDbContext <M3PactContext>(options => options.UseSqlServer(connection));

            DatabaseLoggerSettings dataBaseLoggerSettings = new DatabaseLoggerSettings
            {
                DbSettings = new DbSettings
                {
                    Columns = new List <Column> {
                        new Column {
                            MapTo = "Time", Name = "Time", Type = "DATETIME"
                        },
                        new Column {
                            MapTo = "LogLevel", Name = "LogLevel", Type = "TEXT"
                        },
                        new Column {
                            MapTo = "Message", Name = "Message", Type = "TEXT"
                        },
                        new Column {
                            MapTo = "Exception", Name = "Exception", Type = "TEXT"
                        },
                        new Column {
                            MapTo = "StackTrace", Name = "StackTrace", Type = "TEXT"
                        },
                    },
                    ConnectionString = connection,
                    TableName        = "Log"
                },
                LogLevel = M3Pact.LoggerUtility.LogLevel.Error
            };

            services.AddDbContext <M3PactContext>(options => options.UseSqlServer(connection));
            services.AddLogger(
                new CompoisteLoggerSettings(
                    new List <LoggerSettings> {
                dataBaseLoggerSettings
            }));
            services.RegisterServices();
        }
Example #4
0
 /// <summary>
 /// Initializes the instance variables
 /// </summary>
 /// <param name="level">Log level of the log to be recored</param>
 public DatabaseHelper(DatabaseLoggerSettings settings) : base(settings.LogLevel)
 {
     this.dbSettings = settings.DbSettings;
 }