弄清楚了 Serilog 的基础知识。现在尝试添加一些丰富器,以便我可以在每个日志行中打印用户名或机器名或类名等。
这是我到目前为止的代码,
using System;
using Serilog;
using Serilog.Sinks.SystemConsole;
using Serilog.Sinks.File;
using Serilog.Enrichers;
using Serilog.Core;
using Serilog.Events;
using System.Threading;
using Serilog.Context;
var outputTemplate = "{MachineName} | {UserName} | {Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u4}] | {ClassName} | {Message:l}{NewLine}{Exception}";
var Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console(outputTemplate: outputTemplate)
.WriteTo.File("logFile-.log",
outputTemplate: outputTemplate)
.Enrich.FromLogContext()
.Enrich.WithEnvironmentUserName()
.Enrich.WithProperty("Version", "1.0.0")
.CreateLogger();
Logger.Information("Hello, Serilog!");
var position = new { Latitude = 25, Longitude = 134 };
var elapsedMs = 35;
for (int i = 0; i < 5; i++) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个显示TableData模型行数据的组件,
export class TableData{
constructor(
public id: number,
public country: string,
public capital: string){ }
}
Run Code Online (Sandbox Code Playgroud)
我在这个组件中有我的数据,
tableData: TableData[] = [
new TableData(1, 'Canada','Ottawa'),
new TableData(2, 'USA','Washington DC'),
new TableData(3, 'Australia','Canberra'),
new TableData(4, 'UK','London')
];
Run Code Online (Sandbox Code Playgroud)
然后在我的组件中,我正在创建一个这样的表,
<table>
<tbody>
<tr *ngFor="#row of tableData>
<td contenteditable='true'>{{ row.id }}</td>
<td contenteditable='true' (click)="onRowClick($event)">{{ row.country }}</td>
<td contenteditable='true'>{{ row.capital }}</td>
</tr>
</tbody>
<span>{{ tableData | json }}</span>
</table>
onRowClick(event){
console.log(event);
}
Run Code Online (Sandbox Code Playgroud)
我能够编辑数据,因为我将<td>
元素标记为'contenteditable',但不知道如何保存或检索更新的值.我检查了传递给onRowClick方法的'event'数据,但是无法检索row的'id'(它是空的.event.srcElement.id或event.target.id都是空的).
简而言之,我想编辑表并看到它更新tableData变量.很抱歉没有第一次清楚地问清楚.
任何关于如何解决我的问题的指导非常感谢!
尝试创建特定的新 jira 票证requestType
,但它嵌套了两层深。尝试了一些可能的改变,但没有运气。这是我的代码,
require 'jira-ruby' # https://github.com/sumoheavy/jira-ruby
options = {
:username => jira_username,
:password => jira_password,
:site => 'https://jiraurl/rest/api/2/',
:context_path => '',
:auth_type => :basic,
:read_timeout => 120
}
client = JIRA::Client.new(options)
issue = client.Issue.build
fields_options = {
"fields" =>
{
"summary" => "Test ticket creation",
"description" => "Ticket created from Ruby",
"project" => {"key" => "AwesomeProject"},
"issuetype" => {"name" => "Task"},
"priority" => {"name" => "P1"},
"customfield_23070" =>
{
"requestType" => {
"name" => "Awesome Request Type" …
Run Code Online (Sandbox Code Playgroud) 不知道为什么我这样做了,但我昨天更新到了 .Net Core 2.1。自从我更新后,我在 mac 上的 Visual Studio 中的整个解决方案中看到了大量的波浪线(太烦人了)。这是警告信息 -
我想了解警告的来源。基本上,我参考了很多 3rd 方 Nuget 包(Autofac、Serilog 等),它们是用旧版本的 .Net Core 构建的。这就是我认为的警告试图告诉我的。但是我的代码工作得很好,运行它没有任何问题。
经过一番研究,我认为错误是CS1701。在我的解决方案中的所有项目的编译器设置中,它还添加 [默认] 被忽略。这就是为什么我在构建项目/解决方案时没有看到此警告的原因。但是,波浪线仍会显示在 Visual Studio 的文本编辑器中。
Visual Studio 提供了一种解决方案来抑制这些波浪线,方法是在.cs
文件的顶部添加 pragma 语句- #pragma warning disable CS1701 // Assuming assembly reference matches identity
. 但恐怕我需要将此行添加到.cs
我的解决方案中的所有文件中(有很多)。
有谁知道在文本编辑器中抑制这些波浪线的其他更好的方法吗?
刚开始使用Autofac!我想在多个类中使用相同的Logger实例,但Autofac在不同的类中为我提供了一个新的Logger实例.
IocBuilder.cs
public static class IoCBuilder
{
public static IContainer Container()
{
var logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Console(outputTemplate: outputTemplate)
.WriteTo.File("logs/log-.log",
outputTemplate: outputTemplate,
rollingInterval: RollingInterval.Day)
.CreateLogger();
// Container
var builder = new ContainerBuilder();
builder.RegisterInstance(logger).As<ILogger>().SingleInstance();
builder.RegisterType<MyOtherClass>().SingleInstance();
return builder.Build();
}
}
Run Code Online (Sandbox Code Playgroud)
MyOtherClass.cs
public class MyOtherClass
{
public ILogger Logger {get; set; }
public MyOtherClass(ILogger logger)
{
Logger = logger;
}
public void FirstMethod()
{
Logger.Information("MyOtherClass- FirstMethod");
}
public void SecondMethod()
{
Logger.Information("MyOtherClass - SecondMethod");
}
}
Run Code Online (Sandbox Code Playgroud)
Program.cs中
public static IContainer Container
{ …
Run Code Online (Sandbox Code Playgroud) 刚开始使用 Google Play API。试图让他们的样本工作。
https://developers.google.com/api-client-library/dotnet/get_started
他们的using
声明,
using System;
using System.Threading.Tasks;
using Google.Apis.Discovery.v1;
using Google.Apis.Discovery.v1.Data;
using Google.Apis.Services;
Run Code Online (Sandbox Code Playgroud)
还有行不通的行 -
var service = new DiscoveryService(new BaseClientService.Initializer
{
ApplicationName = "Discovery Sample",
ApiKey = "[YOUR_API_KEY_HERE]",
});
foreach (DirectoryList.ItemsData api in result.Items)
Run Code Online (Sandbox Code Playgroud)
不确定它是否对任何人都有效,但我似乎无法找到DiscoveryService
和 的命名空间DirectoryList
。
有谁知道DiscoveryService
和DirectoryList
属于哪个命名空间?我尝试在对象浏览器中进行探索,但无法找到这些类/方法。
我试图了解如何进行这项工作:
def someMethod() -> dict[any, any]:
if not os.path.exists('some path'):
return {}
config = {'a': 1, 'b': 2}
return config
Run Code Online (Sandbox Code Playgroud)
我认为这是不正确的。看到这个错误——Declared return type, "dict[Unknown, Unknown]", is partially unknownPylance
这个想法是,如果路径不存在(或在某些条件下),则返回空字典,或者使用键值对纠正字典。
有任何想法吗?
刚刚开始研究 RxJS 并试图理解它filter
。https://rxjs-dev.firebaseapp.com/api/operators/filter
从表面上看,没有什么需要弄清楚的,我知道吗?:S
这就是我所拥有的——
declare interface App {
id: string;
bId: string;
account: string;
title: string;
platform: string;
isLive: boolean;
}
Run Code Online (Sandbox Code Playgroud)
public allApps: Observable<App[]>;
this.allApps = this.httpClient.get(`${UtilitiesService.APIRoot}/globals/apps`).pipe(
map( response => response as App[] )
);
Run Code Online (Sandbox Code Playgroud)
这get/pipe/map
让我得到了对象并将其正确地转换为App[]
数组。到目前为止没有任何问题!
现在我想filter
退出bid !== null
并且只有有效值this.allApps
。所以我“尝试”将输出传递map
给filter
这样的 -
this.allApps = this.httpClient.get(`${UtilitiesService.APIRoot}/globals/apps`).pipe(
map( response => response as App[] ),
filter( app => app.bid === null)
);
Run Code Online (Sandbox Code Playgroud)
就我的阅读/YouTube 视频而言,map
( )的输出 …