Anotar 开源项目使用教程
1. 项目的目录结构及介绍
Anotar 项目的目录结构如下:
Anotar/
├── Anotar.CommonLogging/
│ ├── Anotar.CommonLogging.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── LogTo.cs
├── Anotar.Catel/
│ ├── Anotar.Catel.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── LogTo.cs
├── Anotar.NLog/
│ ├── Anotar.NLog.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── LogTo.cs
├── Anotar.Log4Net/
│ ├── Anotar.Log4Net.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── LogTo.cs
├── Anotar.Serilog/
│ ├── Anotar.Serilog.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── LogTo.cs
├── Anotar.Splat/
│ ├── Anotar.Splat.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── LogTo.cs
├── Anotar.LibLog/
│ ├── Anotar.LibLog.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── LogTo.cs
├── Anotar.MetroLog/
│ ├── Anotar.MetroLog.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── LogTo.cs
├── Anotar.Custom/
│ ├── Anotar.Custom.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── LogTo.cs
├── Anotar.Fody/
│ ├── Anotar.Fody.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── ModuleWeaver.cs
├── Anotar.Fody.Tests/
│ ├── Anotar.Fody.Tests.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── Tests.cs
├── Anotar.Fody.nuspec
├── README.md
└── LICENSE
目录结构介绍
Anotar.CommonLogging/
,Anotar.Catel/
,Anotar.NLog/
,Anotar.Log4Net/
,Anotar.Serilog/
,Anotar.Splat/
,Anotar.LibLog/
,Anotar.MetroLog/
,Anotar.Custom/
: 这些目录包含了针对不同日志框架的适配器。Anotar.Fody/
: 包含了 Fody 插件的核心实现。Anotar.Fody.Tests/
: 包含了测试用例。Anotar.Fody.nuspec
: 用于生成 NuGet 包的配置文件。README.md
: 项目说明文档。LICENSE
: 项目许可证。
2. 项目的启动文件介绍
Anotar 项目的启动文件主要是 ModuleWeaver.cs
,位于 Anotar.Fody/
目录下。这个文件是 Fody 插件的核心实现,负责在编译时注入日志代码。
ModuleWeaver.cs 文件介绍
public class ModuleWeaver : BaseModuleWeaver
{
public override void Execute()
{
// 执行具体的注入逻辑
}
public override IEnumerable<string> GetAssembliesForScanning()
{
// 返回需要扫描的程序集列表
}
public override bool ShouldCleanReference => true;
}
Execute()
: 执行具体的注入逻辑。GetAssembliesForScanning()
: 返回需要扫描的程序集列表。ShouldCleanReference
: 是否清理引用。
3. 项目的配置文件介绍
Anotar 项目的配置文件主要是 Anotar.Fody.nuspec
,用于生成 NuGet 包。