C# 非直瞄测井,不记录

C# 非直瞄测井,不记录,c#,aop,nlog,postsharp,C#,Aop,Nlog,Postsharp,我发现了问题所在。代码没有问题。我在查询中写入列名的问题不正确。我不知道我怎么会错过这样一件事,但谢谢你的帮助。如果需要,您可以使用NLog的代码 (我尝试使用NLog登录AOP。我使用Winform并使用Postsharp.NLog代码登录ExceptionLoggingAttribute.cs。该代码在Form1.cs中学习,但在Aspect中不起作用。请帮助我!) 内部AOP 名称空间日志库 { [可序列化] 公共类ExceptionLoggingAttribute:OneExceptio

我发现了问题所在。代码没有问题。我在查询中写入列名的问题不正确。我不知道我怎么会错过这样一件事,但谢谢你的帮助。如果需要,您可以使用NLog的代码

(我尝试使用NLog登录AOP。我使用Winform并使用Postsharp.NLog代码登录ExceptionLoggingAttribute.cs。该代码在Form1.cs中学习,但在Aspect中不起作用。请帮助我!)

内部AOP

名称空间日志库
{
[可序列化]
公共类ExceptionLoggingAttribute:OneExceptionSpect
{
公共流行为{get;set;}
public override void OnException(MethodExecutionArgs args)
{
NLog.Logger Logger=LogManager.GetLogger(“数据库记录器”);
logger.Error(args.Exception.Message);
logger.Fatal(args.Exception.Message);
logger.Debug(args.Exception.Message);
logger.Trace(args.Exception.Message);
args.FlowBehavior=FlowBehavior.Continue;
}
}
Nlog.Configİnside


App.Configİnside



您必须首先启用内部日志,在“信息”上设置
internalLogLevel

如果仍然没有internalLogFile,则NLog无法找到您的NLog.config。请检查NLog.config的位置

或者,您可以这样阅读它:

LogManager.Configuration = new XmlLoggingConfiguration("pathTo_Nlog.config")

或者在C#

上设置配置,我希望这张照片能帮助你理解我


我也遇到了同样的问题。当我执行我的C#console应用程序的main方法(包含以下代码)时,没有创建任何日志:

private static readonly ILog Log = LogManager.GetLogger<Program>();

Log.Info("Application Started . . .");
private static readonly ILog Log=LogManager.GetLogger();
Log.Info(“应用程序已启动…”);
我的问题是NLog.config文件的位置

我右键单击并在Visual Studio中选择了Properties NLog.config。然后,对于“复制到输出目录”属性,选择了“如果更新,则复制”选项

问题是NLog.config文件不在我的应用程序的执行目录中

这描述了如何通过XML规范配置NLog。 特别阅读日志位置部分

我的应用配置:

<sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<common>
    <logging>
      <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog444">
        <arg key="configType" value="INLINE"/>
      </factoryAdapter>
    </logging>
  </common>

和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"
       internalLogLevel="Trace" internalLogFile="d:\NLog_Internallog.txt">
  <variable name="logDirectory" value="logs" />
  <targets>
    <target xsi:type="File"
         name="fileXmlName"
         header="&lt;nlog&gt;"
         footer="&lt;/nlog&gt;"
         fileName="${logDirectory}/${shortdate}.log.xml"
         concurrentWrites="true"
         createDirs="true"
         autoFlush="true">
      <layout xsi:type="Log4JXmlEventLayout">
      </layout>
    </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Trace" writeTo="fileXmlName" />
  </rules>
</nlog>


您的代码是否正在输入方面代码?是,但不起作用。请解释“不起作用”。您期望得到什么?当前结果是什么?我想在程序失败时将错误信息保存在数据库中。但此过程必须在AspectDo中验证内部日志:c:\temp\nlog-internal.log,以查看nlog正在尝试执行的操作。这是一种详细的日志记录,包含有关nlog的所有信息oing。所以最好看一下。它还将记录NLog尝试记录某些内容时发生的任何异常。我的应用程序文件中有NLog.config,但我没有NLog-internal.log文件。此外,NLog在Form1.cs中工作,但在方面代码中不工作。(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"
       internalLogLevel="Trace" internalLogFile="d:\NLog_Internallog.txt">
  <variable name="logDirectory" value="logs" />
  <targets>
    <target xsi:type="File"
         name="fileXmlName"
         header="&lt;nlog&gt;"
         footer="&lt;/nlog&gt;"
         fileName="${logDirectory}/${shortdate}.log.xml"
         concurrentWrites="true"
         createDirs="true"
         autoFlush="true">
      <layout xsi:type="Log4JXmlEventLayout">
      </layout>
    </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Trace" writeTo="fileXmlName" />
  </rules>
</nlog>