public AzureTableStorageErrorLog(IDictionary config)
        {
            if (!(config["storageConnectionString"] is string) ||
                string.IsNullOrWhiteSpace((string)config["storageConnectionString"]))
            {
                throw new ApplicationException("Connection string is missing for the Windows Azure error log.");
            }

            storageConnectionString = config["storageConnectionString"] as string;

            if (!(config["storageTableName"] is string) ||
                string.IsNullOrWhiteSpace((string)config["storageTableName"]))
            {
                throw new ApplicationException("Table name is missing for the Windows Azure error log.");
            }

            storageTableName = config["storageTableName"] as string;

            CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString);
            CloudTableClient    tclient = new CloudTableClient(new Uri(account.TableEndpoint.AbsoluteUri),
                                                               account.Credentials);

            if (!string.IsNullOrEmpty(storageTableName))
            {
                tclient.GetTableReference(storageTableName).CreateIfNotExists();
            }
            else
            {
                throw new ArgumentException("Logs table name not defined in configuration.", "StorageTableName");
            }

            _ctx = new LogServiceContext(account.TableEndpoint.AbsoluteUri, account.Credentials, storageTableName);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Получить данные из БД
        /// </summary>
        /// <returns>List<Log></returns>
        public async Task <List <Log> > Get()
        {
            List <Log> result;

            using (var db = new LogServiceContext())
            {
                result = await db.LogsTable.ToListAsync();
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Записать данные в БД
        /// </summary>
        /// <param name="dt">Дата</param>
        /// <param name="mSize">память в байтах</param>
        /// <returns>
        ///     <see cref="Task" />
        /// </returns>
        public async Task WriteDateAsync(DateTime dt, long mSize)
        {
            using (var db = new LogServiceContext())
            {
                var log = new Log
                {
                    Date       = dt,
                    MemorySize = mSize
                };

                await db.AddAsync(log);

                await db.SaveChangesAsync();
            }
        }
        public override void ActivateOptions()
        {
            base.ActivateOptions();
            System.Diagnostics.Trace.Write("Initializing Azure table storage appender...");

            CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString);
            CloudTableClient    tclient = new CloudTableClient(new Uri(account.TableEndpoint.AbsoluteUri), account.Credentials);

            if (!string.IsNullOrEmpty(storageTableName))
            {
                tclient.GetTableReference(storageTableName).CreateIfNotExists();
            }
            else
            {
                throw new ArgumentException("Logs table name not defined in configuration.", "StorageTableName");
            }

            _ctx = new LogServiceContext(account.TableEndpoint.AbsoluteUri, account.Credentials, storageTableName);
        }