我正在尝试将OpenTracing.Contrib.NetCore与Serilog 一起使用。我需要将自定义日志发送给Jaeger。现在,它仅在我使用默认记录器工厂时才有效Microsoft.Extensions.Logging.ILoggerFactory
我的创业公司:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSingleton<ITracer>(sp =>
{
var loggerFactory = sp.GetRequiredService<ILoggerFactory>();
string serviceName = sp.GetRequiredService<IHostingEnvironment>().ApplicationName;
var samplerConfiguration = new Configuration.SamplerConfiguration(loggerFactory)
.WithType(ConstSampler.Type)
.WithParam(1);
var senderConfiguration = new Configuration.SenderConfiguration(loggerFactory)
.WithAgentHost("localhost")
.WithAgentPort(6831);
var reporterConfiguration = new Configuration.ReporterConfiguration(loggerFactory)
.WithLogSpans(true)
.WithSender(senderConfiguration);
var tracer = (Tracer)new Configuration(serviceName, loggerFactory)
.WithSampler(samplerConfiguration)
.WithReporter(reporterConfiguration)
.GetTracer();
//GlobalTracer.Register(tracer);
return tracer;
});
services.AddOpenTracing();
}
Run Code Online (Sandbox Code Playgroud)
在控制器中的某个位置:
[Route("api/[controller]")]
public class ValuesController : ControllerBase
{
private readonly ILogger<ValuesController> _logger;
public ValuesController(ILogger<ValuesController> logger)
{
_logger = logger;
}
[HttpGet("{id}")] …Run Code Online (Sandbox Code Playgroud) 我正在尝试将规范模式应用于我的验证逻辑.但我在异步验证方面遇到了一些问题.
假设我有一个AddRequest需要验证的实体(有2个字符串属性FileName和Content).
我需要创建3个验证器:
验证FileName是否包含无效字符
验证内容是否正确
异步验证数据库中是否存在具有FileName的文件.在这种情况下,我应该有类似的东西Task<bool> IsSatisfiedByAsync
但我怎么能同时实现IsSatisfiedBy和IsSatisfiedByAsync?我应该创建2个接口ISpecification,IAsyncSpecification或者我可以在一个接口中创建吗?
我的版本ISpecification(我只需和)
public interface ISpecification
{
bool IsSatisfiedBy(object candidate);
ISpecification And(ISpecification other);
}
Run Code Online (Sandbox Code Playgroud)
AndSpecification
public class AndSpecification : CompositeSpecification
{
private ISpecification leftCondition;
private ISpecification rightCondition;
public AndSpecification(ISpecification left, ISpecification right)
{
leftCondition = left;
rightCondition = right;
}
public override bool IsSatisfiedBy(object o)
{
return leftCondition.IsSatisfiedBy(o) && rightCondition.IsSatisfiedBy(o);
}
}
Run Code Online (Sandbox Code Playgroud)
要验证文件是否存在,我应该使用:
await _fileStorage.FileExistsAsync(addRequest.FileName);
Run Code Online (Sandbox Code Playgroud)
IsSatisfiedBy如果我确实需要那个异步,我怎么能写那个支票呢?
例如,这里是FileName的验证器(1)
public …Run Code Online (Sandbox Code Playgroud) c# design-patterns domain-driven-design specification-pattern async-await
我有一张桌子:
Id PersonId Phone IsPrimary
-----------------------------------
1 1 12345 1
2 1 55555 0
3 2 66666 1
4 3 77777 1
5 3 88888 0
6 3 99999 0
Run Code Online (Sandbox Code Playgroud)
如何创建约束,允许在每个PersonId中只插入一个IsPrimary = 1.对于所有PersonId,只有一个IsPrimary = 1.因此,在结果中我将无法插入下一条记录:
Id PersonId Phone IsPrimary
-----------------------------------
1 1 00000 1
Run Code Online (Sandbox Code Playgroud) 我有这3个更新
UPDATE [Person]
SET [Email] = @Prefix
WHERE [Id] = @PersonId AND ISNULL([Email], '') <> ''
UPDATE [Person]
SET [Phone] = @Phone
WHERE [Id] = @PersonId AND ISNULL([Phone], '') <> ''
UPDATE [Person]
SET [Skype] = @Skype
WHERE [Id] = @PersonId AND ISNULL([Skype], '') <> ''
Run Code Online (Sandbox Code Playgroud)
我可以将它合并为一个或如何编写更多性能操作?谢谢
c# ×2
sql-server ×2
t-sql ×2
asp.net-core ×1
async-await ×1
jaeger ×1
opentracing ×1
serilog ×1
sql ×1