我正在尝试让NLog登录到我的数据库日志表但无济于事.我确定我的连接字符串是正确的,因为它与我的web.config中的其他地方一样.写出文件工作正常,所以我知道它不仅仅是NLog,而且必须是我做错了.以下是我的NLog配置:
<!-- NLOG CONFIGURATION -->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File" fileName="${basedir}/logs/Log ${shortdate}.txt" layout="${longdate} ${callsite} ${level}: ${message} ${exception:format=Message,StackTrace} ${stacktrace}" />
<target type="Database" name="database" connectionstring="MyConnectionString">
<commandText>
insert into MyLog ([CreateDate], [Origin], [LogLevel], [Message], [Exception], [StackTrace]) values (@createDate, @origin, @logLevel, @message, @exception, @stackTrace);
</commandText>
<parameter name="@createDate" layout="${longdate}"/>
<parameter name="@origin" layout="${callsite}"/>
<parameter name="@logLevel" layout="${level}"/>
<parameter name="@message" layout="${message}"/>
<parameter name="@exception" layout="${exception:format=Message,StackTrace}"/>
<parameter name="@stackTrace" layout="${stacktrace}"/>
</target>
</targets>
<rules>
<logger name="*" writeTo="file"/>
<logger name="*" appendTo="database"/>
<!--<logger name="*" writeTo="mail" minlevel="Error"/>-->
</rules>
</nlog>
Run Code Online (Sandbox Code Playgroud) 考虑以下代码:
Console.WriteLine("Hello, World!".GetHashCode());
Run Code Online (Sandbox Code Playgroud)
第一次运行:
139068974
第二次运行:
-263623806
现在考虑用 Kotlin 编写的相同内容:
println("Hello, World!".hashCode())
Run Code Online (Sandbox Code Playgroud)
第一次运行:
1498789909
第二次运行:
1498789909
为什么string.NET 中的每次执行的哈希码都会发生变化,但在其他运行时(如 JVM)上却不会发生变化?
是否有库或可接受的方法来清理html页面的输入?
在这种情况下,我有一个只有姓名,电话号码和电子邮件地址的表单.
代码必须是C#.
例如:
"<script src='bobs.js'>John Doe</script>" 应该成为 "John Doe"
我开始使用React Native编程,我习惯使用语法:
async myFunction(){
...
return await otherFunction();
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何使它与共享包中的React JS和React Native兼容.我怎样才能实现这一点,以便它可以在两个平台上运行?
谢谢!
这是一个常见的问题,我希望它已经彻底解决了我.
在我正在为客户端做的系统中,我们希望从不受信任的来源(HTML格式的电子邮件和HTML文件)接受HTML,清理它以使其没有任何脚本,指向外部资源的链接以及其他安全性/等等 问题; 然后安全地显示它,同时不丢失基本格式.例如,就像电子邮件客户端使用HTML格式的电子邮件一样,但理想情况下不会重复在该领域中已经发生的347,821错误(到目前为止).:-)
目标是最终通过iframe我们自己的Web界面或通过.Net Windows窗体应用程序中的WebBrowser类(这似乎不安全,可能不那么)向内部用户显示我们感觉舒适的东西,以下示例.
我们认识到其中一些可能会破坏文本的显示; 没关系.
我们将在接收时清理HTML并存储已清理的版本(不要担心存储部分 - SQL注入等 - 我们已经覆盖了这一点).
该软件需要在Windows Server上运行.COM DLL或.Net程序集首选.FOSS显然是首选,但不是交易破坏者.
到目前为止我发现了什么:
你会为这项任务推荐什么?以上之一?别的什么?
例如,我们想删除以下内容:
script 分子link,img以及与外部资源相关的此类元素(可能会替换img为"[图像已删除]"或其中一些此类文本)embed,object,applet,audio,video,并尝试创建对象的其他标签onclick 和类似的DOM0事件处理程序脚本代码href关于a触发代码的元素(即使是我们认为可以接受的链接,我们也可能会变成用户必须有意复制并粘贴到浏览器中的明文).例如,这个HTML:
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<link rel="stylesheet" type="text/css" …Run Code Online (Sandbox Code Playgroud) 我试图让Json.Net序列化一个没有引号的属性名称,并且发现很难在Google上找到文档.我怎样才能做到这一点?
它只是大型Json渲染的一小部分,所以我更喜欢添加属性属性,或者覆盖类的序列化方法.
目前,它呈现如下:
"event_modal":
{
"href":"file.html",
"type":"full"
}
Run Code Online (Sandbox Code Playgroud)
而且我希望让它呈现如下:( href并且type没有引号)
"event_modal":
{
href:"file.html",
type:"full"
}
Run Code Online (Sandbox Code Playgroud)
来自班级:
public class ModalOptions
{
public object href { get; set; }
public object type { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 如何降低给定代码段的复杂性?我在 Sonarqube 中收到此错误---> 重构此方法以将其认知复杂度从 21 降低到允许的 15。
this.deviceDetails = this.data && {...this.data.deviceInfo} || {};
if (this.data && this.data.deviceInfo) {
this.getSessionInfo();
// tslint:disable-next-line: no-shadowed-variable
const { device, driver, ipAddress, port, active, connectionType } = this.data.deviceInfo;
this.deviceDetails = {
name: device.name || '',
manufacturer: device.manufacturer || '',
deviceType: device.deviceType || '',
model: device.model || '',
description: device.description || '',
managerId: device.deviceManager && device.deviceManager.managerId || null,
locationId: device.location && device.location.locationId || null,
active: device.active,
connectionType: connectionType || null,
driver_id: driver && driver.driverId || …Run Code Online (Sandbox Code Playgroud) 我有几个使用的库Debug.Assert(...).我认为这Debug.Assert(...)很好,我仍然希望它们执行,但我不希望它们阻止我的应用程序的执行.理想情况下,我只希望他们在某处登录.
鉴于我无法更改库的代码(我仍然希望在调试中编译并运行断言),如何阻止Debug.Assert(...)显示模式对话框?
另外,我想确保主程序在Assert发生时继续(与忽略按钮相同的行为).
谢谢!
我公司内部正在与NLog合作.我们遇到了大量日志文件的问题.我们想要做的是按天归档文件并保留最多x个文件.让我们说7.我已经在互联网上阅读了几个关于此的主题,他们主要指向我修改我的NLog.config文件的方向.但是,它似乎不愿意像我期望的那样旋转文件.目前,所需的文件夹中没有任何内容存档.但是所有文件都以以下格式保存在'logs'-directory中;
Log.info.2011-11-07.txt
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,我有一个目录'logs'.在该文件夹中保存所有日志文件.我还有一个名为'archives'的文件夹,我想在其中存档所有旧文件.在该目录中达到最大数量的日志文件后,应自动清除它们.这可能吗?我当前的NLog.config文件如下所示;
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="true"
internalLogFile="C:\nlog-internal.txt"
internalLogLevel="Error">
<extensions>
<add assembly="NLog.Extended" />
</extensions>
<targets>
<!-- will move file to archive once it reaches 1MB. Files are archived by day, with a maximum of three files. ConcurrentWrites is set to false,
change to true if multiple processes will be writing to the logfile-->
<target name="file" xsi:type="File" fileName="${basedir}/logs/Log.info.${shortdate}.txt"
layout="${longdate} ${callsite} ${level}: ${message} ${exception:format=Message,StackTrace} ${stacktrace}"
archiveFileName="${basedir}/logs/archives/log.info.${shortdate}.txt"
archiveAboveSize="1048576"
archiveEvery="Day"
archiveNumbering = "Rolling"
maxArchiveFiles="7"
concurrentWrites="false"
/>
<target name="file-default" xsi:type="File" …Run Code Online (Sandbox Code Playgroud) 我想有一个Windows机器上所有可用时区的列表.我怎么能在.NET中这样做?
我知道TimeZoneInfo.GetSystemTimeZones方法,但这只返回当前选定的时区
DateTimeOffset current = DateTimeOffset.Now;
ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
Console.WriteLine("You might be in the following time zones:");
foreach (TimeZoneInfo timeZoneInfo in timeZones)
{
// Compare offset with offset for that date in that time zone
if (timeZoneInfo.GetUtcOffset(current).Equals(current.Offset))
{
Console.WriteLine(" {0}", timeZoneInfo.DisplayName);
}
}
Run Code Online (Sandbox Code Playgroud) c# ×5
.net ×2
nlog ×2
angular ×1
assert ×1
c#-4.0 ×1
gethashcode ×1
hashcode ×1
html ×1
javascript ×1
json.net ×1
logging ×1
react-native ×1
reactjs ×1
sanitization ×1
sonarlint ×1
sonarqube ×1
timezone ×1
web-config ×1