小编Jul*_*ian的帖子

为什么我的Windows服务不会写入我的日志文件?

我有一个Windows服务并使用nlog进行日志记录.当我从visual studio ide运行时,一切正常.日志文件更新没有问题.当我安装该服务时,该服务运行正常,但日志文件永远不会更新.如果有帮助,我在LOCAL SERVICE下运行.是的,我在我的应用程序文件夹下创建了logs目录.

 <?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" >

  <targets>
    <target name="file" xsi:type="File" fileName="${basedir}/logs/${shortdate}_info.txt"
            layout="${date} ${logger} ${message}" />
  </targets>

  <rules>
    <logger name="*" minlevel="Info" maxlevel="Info" writeTo="file" />
  </rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)

c# service logging windows-services nlog

25
推荐指数
3
解决办法
4万
查看次数

如何配置NLog写入数据库?

我试图让NLOG写入到数据库,但我目前的代码,它抛出一个异常,当我试图调试,例外情况是:为"NotifyIcon.Program"的类型初始值引发异常.

我的NLog配置文件代码如下,因为这似乎是导致问题,因为它是我改变的唯一代码.

<?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">

  <!-- 
  See http://nlog-project.org/wiki/Configuration_file 
  for information on customizing logging rules and outputs.
   -->
  <targets>
    <!-- add your targets here -->

    <target name="database" xsi:type="Database" />
    <target xsi:type="Database"
          name="String"
          dbUserName="Layout"
          dbProvider="sqlserver"
          useTransactions="false"
          connectionStringName="String"
          connectionString="Data Source=AC-02\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"
          keepConnection="true"
          dbDatabase="Layout"
          dbPassword="Layout"
          dbHost="Layout"
          installConnectionString="Layout"
          commandText="INSERT INTO Logs (Machine_Name, Username, Logon_Time, Screensaver_On, Screensaver_Off, Logoff_Time, Program_Start) Values @MachineName, @Username, @LogonTime, @Screensaver_On, @Screensaver_Off, @LogoffTime, @ProgramStart "/>

  </targets>

  <rules>

    <logger name="*" minlevel="Trace" writeTo="database" />

  </rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)

任何和所有的帮助将不胜感激=]

c# database nlog

25
推荐指数
2
解决办法
4万
查看次数

在NLog文件路径中使用app data目录

如何target在NLog.config文件中设置以在用户应用程序数据目录中创建日志文件?

下面是文件的所需位置.

C:\用户\用户ID \应用程序数据\本地...\LOGFILE.TXT

我尝试fileName以下列方式设置,但没有成功.

  • target name="logfile" xsi:type="File" fileName="%APPDATA%/.../LogFile.txt"

  • target name="logfile" xsi:type="File" fileName="${APPDATA}/.../LogFile.txt"

  • target name="logfile" xsi:type="File" fileName="${%APPDATA%}/.../LogFile.txt"

logging nlog

25
推荐指数
2
解决办法
2万
查看次数

NLog会在所有aspnet布局渲染器上抛出配置异常

我一直在努力在我的ASP.NET MVC 3应用程序上设置NLog v2,到目前为止它运行良好.(我使用的是来自官方的NuGet库包).然而,当我尝试更改日志布局包括任何aspnet-*布局渲染器,我得到一个配置错误.我已将问题减少到以下最小用例:

在configSections块中:

<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
Run Code Online (Sandbox Code Playgroud)

Nlog块:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">

<variable name="logDirectory" value="C:\Logs" />
<targets>
  <target name="logFile" xsi:type="File" fileName="${logDirectory}\app.log"
      layout="${aspnet-user-identity}" />
</targets>       

<rules>
  <logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
Run Code Online (Sandbox Code Playgroud)

如果我改变布局中使用不属于ASPNET*家族的一部分渲染器的任意组合,这个效果很好(我没有测试过的每一个,但我已经看了不少).我得到的错误在这里:

Configuration Error 
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: An error occurred creating the configuration section handler for nlog: Exception occurred …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc nlog asp.net-mvc-3

23
推荐指数
3
解决办法
1万
查看次数

如何在.Net Core项目中禁用TypeScript编译?

我有一个Visual Studio 2015 ASP.Net核心项目,其中包含一个打字稿文件的文件夹.

我的问题是如何阻止VS尝试编译TypeScript文件?我不希望它们在保存或构建时编译.

我尝试在下面添加了项目设置,但它似乎没有任何影响.

<PropertyGroup>
  <TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

目前VS正在抛出错误,tsc.exe exited with code 1但如上所述,我不希望TS编译器完全运行.

我可以禁用VS使用的typescript.targets,但这不实用,因为我需要它用于其他项目.

visual-studio-2015 .net-core asp.net-core-1.0

23
推荐指数
1
解决办法
9069
查看次数

如何将非核心csproj转换为VS2017格式

我在VS2015有两个项目

  1. 一个.NET Core(project.json,xproj)
  2. 一个常规的.NET csproj

当我用VS2017打开项目1时,它很好地迁移到新的csproj格式.

Project 2适用于VS2017,但我喜欢将此csproj转换/迁移/更新为新的项目文件格式,以便受益于新的csproj功能(多目标,无大文件列表,可读csproj,csproj中的NuSpec信息等)

我怎么能这样做?我在VS2017中找不到一个选项.

使用:VS2017 RTM

upgrade csproj visual-studio-2017

22
推荐指数
2
解决办法
6702
查看次数

将Range或DocumentFragment转换为字符串

有没有办法在W3C兼容的浏览器中获取JavaScript范围对象的html字符串?

例如,假设用户选择以下内容:Hello <b>World</b>
可以使用该Range.toString()方法将"Hello World"作为字符串.(在Firefox中,也可以使用文档getSelection方法.)

但我似乎无法找到获取内部HTML的方法.

经过一番搜索,我发现范围可以转换为DocumentFragmentObject.

但是DocumentFragments没有innerHTML属性(至少在Firefox中;没有尝试过Webkit或Opera).
这对我来说似乎很奇怪:显然应该有一些方法来访问所选项目.

我意识到我可以创建一个documentFragment,将文档片段附加到另一个元素,然后获取该innerHTML元素.
但该方法将自动关闭我选择的区域内的任何打开的标签.
除此之外,肯定有一个明显的"更好的方法",而不是将它附加到dom只是为了让它成为一个字符串.

那么,如何获取Range或DocFrag的html字符串?

javascript range tostring selection documentfragment

20
推荐指数
5
解决办法
2万
查看次数

Visual Studio - 如何在发布模式下删除引用

我正在开发一个用于其他应用程序的库,由于NLog,这个库有很多调试和日志记录语句.

当我切换到发布模式时,是否可以排除对NLog.dll的引用?

干杯,

msbuild release release-management visual-studio

19
推荐指数
1
解决办法
3916
查看次数

BackgroundService .net core 中 ExecuteAsync 和 StartAsync 方法的区别

从旧版 .NET Framework 迁移,我需要创建一个长时间的后台进程工作者。

查看文档我发现了一个BackgroundService类,用于这种目的。但是我偶然发现了两种相同的(就我的观点而言)方法ExecuteAsync()StartAsync()

有人可以向我解释它们之间的主要区别吗?是不是某种隔离原则——我们有一种将数据设置为“构造函数”的方法,我们有一种实际做事的方法?

c# migration backgroundworker .net-core

19
推荐指数
1
解决办法
6768
查看次数

更好的TypeInitializationException(innerException也为null)

介绍

当用户在NLog的配置中创建错误(如无效的XML)时,我们(NLog)抛出一个NLogConfigurationException.该例外包含描述错误的内容.

但有时如果第一次调用NLog来自静态字段/属性,则会NLogConfigurationException被"吃掉" System.TypeInitializationException.

例如,如果用户有此程序:

using System;
using System.Collections.Generic;
using System.Linq;
using NLog;

namespace TypeInitializationExceptionTest
{
    class Program
    {
        //this throws a NLogConfigurationException because of bad config. (like invalid XML)
        private static Logger logger = LogManager.GetCurrentClassLogger();

        static void Main()
        {
            Console.WriteLine("Press any key");
            Console.ReadLine();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并且配置中存在错误,NLog抛出:

throw new NLogConfigurationException("Exception occurred when loading configuration from " + fileName, exception);
Run Code Online (Sandbox Code Playgroud)

但是用户会看到:

抛出异常

"将异常详细信息复制到剪贴板":

System.TypeInitializationException未处理消息:mscorlib.dll中发生未处理的类型'System.TypeInitializationException'的异常附加信息:'TypeInitializationExceptionTest.Program'的类型初始值设定项引发异常.

所以消息消失了!

问题

  1. 为什么innerException不可见?(在Visual Studio 2013中测试).
  2. 我可以发送更多信息TypeInitializationException吗?像一条消息?我们已经发送了一个innerException.
  3. 我们可以使用另一个例外或是否有属性,Exception以便报告更多信息? …

c# exception nlog

17
推荐指数
2
解决办法
4984
查看次数