Logging/LogDatabase.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System.Collections.Generic;
using System.Data;
using System.Data.Linq;
using ComLib.Entities;
using ComLib.Data;
namespace ComLib.Logging
{
/// <summary>
/// This class represents a logger that can log
/// messages to a database.
/// </summary>
public class LogDatabase : LogBase
{
private const int FlushInterval = 5;
// private readonly IDbConnection _connection;
private IList<LogEventEntity> _uncommitedList;
private IRepository<LogEventEntity> _repo;
/// <summary>
/// Constructor
/// </summary>
/// <param name="appName">Name of application.</param>
/// <param name="name">Logger name.</param>
/// <param name="connectionString">Connection string to a database that contains the log events table</param>
/// <param name="logLevel">Log level to use.</param>
public LogDatabase(string appName, string name, string connectionString, LogLevel logLevel)
{
// Initialize with real Database using the RepositoryLinq2Sql.
var conInfo = new ConnectionInfo(connectionString);
_repo = new RepositoryLinq2Sql<LogEventEntity>(conInfo, new Database());
Init(appName, name, logLevel);
}
/// <summary>
/// Constructor taking the IRepository that will handle CRUD operations
/// of log messages to the Database.
/// Also, the repo provided can be a FAKE( In-Memory ) implementation which
/// is useful in testing.
/// </summary>
/// <param name="appName">Name of application.</param>
/// <param name="name">Logger name.</param>
/// <param name="logLevel">Log level to use.</param>
/// <param name="repo"></param>
public LogDatabase(string appName, string name, IRepository<LogEventEntity> repo, LogLevel logLevel)
{
_repo = repo;
Init(appName, name, logLevel);
}
private void Init(string appName, string loggerName, LogLevel logLevel)
{
this.Name = string.IsNullOrEmpty(loggerName) ? "db" : loggerName;
var settings = new LogSettings();
settings.AppName = appName;
后面还有 52 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
