Serilog with Autofac
http://serilog.net/ ---不错的日志工具
1.直接绑定
builder.Register<ILogger>((c, p) =>
{
return new LoggerConfiguration()
.WriteTo.RollingFile(
AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "/Log-{Date}.txt")
.CreateLogger();
}).SingleInstance();
http://docs.autofac.org/en/latest/register/registration.html#selection-of-an-implementation-by-parameter-value
2.使用 AutofacSerilogIntegration
nuget安装 Install-Package AutofacSerilogIntegration
static void Main()
{
Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("SourceContext", null)
.WriteTo.LiterateConsole(
outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {Message} ({SourceContext:l}){NewLine}{Exception}")
.CreateLogger(); try
{
var builder = new ContainerBuilder();
builder.RegisterLogger(autowireProperties: true);
builder.RegisterType<AcceptsLogViaCtor>().As<IExample>();
builder.RegisterType<AcceptsLogViaProperty>().As<IExample>(); using (var container = builder.Build())
{
var examples = container.Resolve<IEnumerable<IExample>>();
foreach (var example in examples)
{
example.Show();
}
}
}
catch (Exception ex)
{
Log.Error(ex, "Unhandled error");
}
}
Serilog with Autofac的更多相关文章
- 在asp.net web api 2 (ioc autofac) 使用 Serilog 记录日志
Serilog是.net里面非常不错的记录日志的库,另外一个我认为比较好的Log库是NLog. 在我个人的asp.net web api 2 基础框架(Github地址)里,我原来使用的是NLog,但 ...
- 在asp.net web api 2 使用 Serilog 记录日志
Serilog是.net里面非常不错的记录日志的库,另外一个我认为比较好的Log库是NLog. 在我个人的asp.net web api 2 基础框架(Github地址)里,我原来使用的是NLog,但 ...
- Serilog 记录日志
Serilog 记录日志 Serilog是.net里面非常不错的记录日志的库,另外一个我认为比较好的Log库是NLog. 在我个人的asp.net web api 2 基础框架(Github地址)里, ...
- [译]Serilog Tutorial
在过去的几年中,结构化日志已经大受欢迎.而Serilog是 .NET 中最著名的结构化日志类库 ,我们提供了这份的精简指南来帮助你快速了解并运用它. 0. 内容 设定目标 认识Serilog 事件和级 ...
- 结构化日志类库 ---- Serilog库
在过去的几年中,结构化日志已经大受欢迎.而Serilog是 .NET 中最著名的结构化日志类库 ,我们提供了这份的精简指南来帮助你快速了解并运用它. 0. 内容 设定目标 认识Serilog 事件和级 ...
- 七、.net core(.NET 6)使用Serilog进行配置和实现日志记录
使用Serilog来实现日志记录 先安装Serilog六件套神装包: 也可以对个别相应的包进行删除等,都是可以的.例如,标注的1是读取配置文件的,如果不需要通过配置文件进行操作,就可以使用这个包.2是 ...
- AutoFac在项目中的应用
技能大全:http://www.cnblogs.com/dunitian/p/4822808.html#skill 完整Demo:https://github.com/dunitian/LoTCode ...
- Autofac - MVC/WebApi中的应用
Autofac前面写了那么多篇, 其实就是为了今天这一篇, Autofac在MVC和WebApi中的应用. 一.目录结构 先看一下我的目录结构吧, 搭了个非常简单的架构, IOC(web), IBLL ...
- Autofac - 生命周期
实例生命周期决定在同一个服务的每个请求的实例是如何共享的. 当请求一个服务的时候,Autofac会返回一个单例 (single instance作用域), 一个新的对象 (per lifetime作用 ...
随机推荐
- Using Apache Web Server with Jboss AS 7
In real-world projects, it's common to find Apache web server as a front door to your application se ...
- springboot的restController使用swagger遇到的问题。
在controller中使用swagger,使用注解ApiImplicitParam遇到一个问题 当方法的参数是走path的swggerui的参数展现是正常的, @PathVariable 但如果是走 ...
- 使用Array
public class UsingArray { public static void output(int[]Array) { if(Array!=null) ...
- Girls' research - HDU 3294 (Manacher处理回文串)
题目大意:给以一个字符串,求出来这个字符串的最长回文串,不过这个字符串不是原串,而是转换过的,转换的原则就是先给一个字符 例如 'b' 意思就是字符把字符b转换成字符 a,那么c->b, d-& ...
- ASIHttpRequest或者SDWebImage给UIImageView加载图片的逻辑是什么样子的
非常非常喜欢SDWebImage,就算后来AF也做了图片缓存,我也还是一直使用.图片缓存真的是一件令人头疼的事,但是SDWebImage封装了一切,你所需要的只是简单的set一个URL:1.设置一个展 ...
- UITextField知多少
//初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...
- PyCharm4注册码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 name : newasp == ...
- ARC简介以及工程中ARC与非ARC的混合
Piosa 博客园 博问 闪存 首页 新随笔 联系 管理 订阅 随笔- 79 文章- 0 评论- 13 ARC简介以及工程中ARC与非ARC的混合 ARC与非ARC在一个项目中同时使用, ...
- 2015 UESTC Winter Training #10【Northeastern Europe 2009】
2015 UESTC Winter Training #10 Northeastern Europe 2009 最近集训都不在状态啊,嘛,上午一直在练车,比赛时也是刚吃过午饭,状态不好也难免,下次比赛 ...
- try{...} catch {...} finally{...} 各种情况代码的执行情况
try { int i = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("in the 'try'"); } ca ...