Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
113 views
in Technique[技术] by (71.8m points)

c# - nlog failing on production server

I have setup my asp.Net Core 5 application with Nlog for logging errors on LIVE environment. It has been working smoothly till recently when I realized that the hosting company reconfigured permissions to folders on the server, denying write permissions to some folders. I started noticing that I was no longer able to upload files to some of the folders I had under www folder in the application.

When I brought their attention to it, they enabled write access to that folder and since then, I can upload files but I also noticed that at about the same time, my error logging stopped working. Locally, my error logging still works but not working on the production server anymore.

Now I wish to find out whether the error logging can be affected by the review of write permissions and how I might be able to troubleshoot the issue further and probably make some reasonable suggestions to the technical support team to help resolve the issue faster.

My Nlog configuration file is as follows

<?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"
  internalLogLevel="Info"
  internalLogFile="c:empinternal-nlog.txt">

 <!-- enable asp.net core layout renderers -->
 <extensions>
  <add assembly="NLog.Web.AspNetCore" />
  <add assembly="NLog.MailKit" />
  </extensions>

 <!-- the targets to write to -->
 <targets>
 <!-- write logs to file  -->
 <target xsi:type="File" name="alllogs" fileName="./logs/all-logs/${shortdate}.log"
        layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />

<!-- another file log, only own logs. Uses some ASP.NET core renderers -->
<target xsi:type="File" name="errorlogs" fileName="./logs/error-logs/${shortdate}.log"
        layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />

<!-- Database Logging target -->
<target name="db" xsi:type="Database"
        dbHost="hosteserver"
        dbDatabase="databasename"
        dbUserName="username"
        dbPassword="password">
 
  <commandText>
    insert into dbo.ErrorLogs (
    Logtime, Level, Message, Exception,
    Logger
    ) values (
    @TimeLogged, @Level, @Message, @Exception,
    @Logger
    );
  </commandText>
  <parameter name="@TimeLogged" layout="${longdate}" />
  <parameter name="@Level" layout="${level}" />
  <parameter name="@Message" layout="${message}" />
  <parameter name="@Exception" layout="${exception:tostring}" />
  <parameter name="@Logger" layout="${logger}" />
</target>

<!-- my mailkit target for email notifications on error -->
<target xsi:type="Mail"
     name="ErrorMailLogTarget"        
     subject="Error Occurred on The Application Name"
     to="[email protected]"
    
     from="[email protected]"
     body="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}"
     smtpUserName="[email protected]"
      smtpServer="mydomain.com"
      smtpPort="587"
     timeout="20000"         
     smtpPassword="email_password"
     smtpAuthentication="basic"
     skipCertificateValidation="true"
     priority="Urgent"
   />
 </targets>

 <!-- rules to map from logger name to target -->
 <rules>
  <!--All logs, including from Microsoft-->
  <logger name="*" minlevel="Trace" writeTo="alllogs" />

<!--Skip non-critical Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" maxlevel="Info" final="true" />

<!-- BlackHole without writeTo -->
<logger name="*" minlevel="Error" writeTo="errorlogs" />

<!-- Error Mail notification log -->
<logger name="*" minlevel="Error" writeTo="ErrorMailLogTarget" />

<!-- Database Logging Provision -->
<logger name="*" minlevel="Error" writeTo="db" />
 </rules>
 </nlog>

I will appreciate any guide to resolve this.

Thank you

question from:https://stackoverflow.com/questions/65928105/nlog-failing-on-production-server

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...