Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target filename does not seem to like certain characters - NLog Asp.NET Core 4.5.3 #285

Closed
oggythorpe1610 opened this issue May 2, 2018 · 5 comments

Comments

@oggythorpe1610
Copy link

oggythorpe1610 commented May 2, 2018

Type Bug

NLog.Web.AspNetCore version: 4.5.3

NLog.Extensions.Logging version: 1.0.1

Platform: .NET Core 2

Current NLog config (xml)

<?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="Warn"
      internalLogFile="nlog_internal.log">

  <extensions>
    <add assembly="NLog.Web.AspNetCore"/>
  </extensions>
  
  <targets>

    <target xsi:type="Console"
            name="Console"
            layout="${message}" />

    <target name="Mail"
            to="#{emailTo}"
            from="#{emailFrom}"
            html="false"
            subject="Hercules Web Services Error - #{Octopus.Environment.Name} - ${logger}"
            body="${message}"
            smtpUsername="#{smtpUsername}"
            smtpPassword="#{smtpPassword}"
            Encoding="UTF-8"
            smtpAuthentication="Basic"
            enableSsl="#{enableSsl}"
            smtpServer="#{smtpServer}"
            smtpPort="#{smtpPort}" />

    <target name="WebServicesLogFile"
            xsi:type="File"
            fileName="#{WebServices.Logging.Root}\WebServicesLogFile_${shortdate}.log"
            layout="${longdate} ${level:uppercase=true} ${threadid} ${logger} - ${message}" 
            keepFileOpen="true"
            encoding="utf-8"
            maxArchiveFiles="4"
            archiveAboveSize="10240"
            archiveEvery="Day"/>

    <target name="OrderServiceLogFile"
            xsi:type="File"
            fileName="#{WebServices.Logging.Root}\OrderServiceLogFile_${shortdate}.log"
            layout="${longdate}|${logger}|${uppercase:${level}}|${message} ${exception}" 
            keepFileOpen="true"
            encoding="utf-8"
            maxArchiveFiles="4"
            archiveAboveSize="10240"
            archiveEvery="Day"/>

  </targets>

  <rules>

    <logger name="WebServicesLog" minlevel="Info" writeTo="WebServicesLogFile" />
    <logger name="OrderServiceLog" minlevel="Info" writeTo="OrderServiceLogFile" />

    <logger name="*" minlevel="Error" writeTo="Mail" />
    <logger name="*" minlevel="Info" writeTo="Console" />

  </rules>
</nlog>

#{WebServices.Logging.Root} are replaced by Octopus with a valid path.

Current result, target filename for log files when containing braces in the path causes a log file name to be written incorrectly. So a filename of C:\Logs\UAT (Testing)\Debuglog.log will be written as C:\Logs\UAT (Testing).

Expected result, target filename should accept valid filename characters in the path so that a filename of C:\Logs\UAT (Testing)\Debuglog.log will be written as C:\Logs\UAT (Testing)\Debuglog.log.

Changing the path in the config to C:\Logs\Debuglog.log allows the correect log file to be written.

@304NotModified
Copy link
Member

#{WebServices.Logging.Root} are replaced by Octopus with a valid path.

I'm a bit confused. NLog is loaded before replacing with octopus?

So a filename of C:\Logs\UAT (Testing)\Debuglog.log will be written as C:\Logs\UAT (Testing).

Which target could result in C:\Logs\UAT (Testing)\Debuglog.log?

@snakefoot
Copy link
Contributor

snakefoot commented May 2, 2018

@oggythorpe1610 Have you checked the NLog Internal Logger to see how it parses the input? It will show the parsed layout and the filenames being created. See https://github.com/NLog/NLog/wiki/Internal-Logging

@304NotModified
Copy link
Member

bump @oggythorpe1610

@304NotModified
Copy link
Member

304NotModified commented May 10, 2018

see also NLog/NLog#2714 - it just works.

@304NotModified
Copy link
Member

Closing this due to inactivity. Please let us know if this still an issue and please provide the requested info -
thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants