# 快速入门

# 安装

Install-Package CanalSharp
1

# 初始化日志

var loggerFactory = LoggerFactory.Create(builder =>
{
    builder
        .AddFilter("Microsoft", LogLevel.Debug)
        .AddFilter("System", LogLevel.Information)
        .AddConsole();
});
var logger= loggerFactory.CreateLogger<SimpleCanalConnection>();
1
2
3
4
5
6
7
8

CanalSharp 使用 Microsoft.Extensions.Logging.Abstractions ,因为目前主流日志组件,如:nlog、serilog 等,全部支持此日志抽象接入,也就是说你可以通过安装 nlog、serilog 对其的适配,来使用它们,无论是 Console App 或则是 Web App。

# 创建连接

var conn=new SimpleCanalConnection(new SimpleCanalOptions("127.0.0.1",11111,1234),logger);
//连接到 Canal Server
await conn.ConnectAsync();
//订阅
await conn.SubscribeAsync();
1
2
3
4
5

# 获取数据

var msg = await conn.GetAsync(1024);
1

Demo: SimpleApp (opens new window)