Skip to content

Commit

Permalink
Merge pull request #62 from SkillsFundingAgency/CON-2001-nLog-fix
Browse files Browse the repository at this point in the history
Added dev / deployed nLog config
  • Loading branch information
narendranogothu authored Jul 8, 2020
2 parents 2734a98 + be22e53 commit d43a259
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/SFA.DAS.Notifications.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class Program
{
public static void Main(string[] args)
{
var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var logger = NLogBuilder.ConfigureNLog(environment == "Development" ? "nlog.Development.config" : "nlog.config").GetCurrentClassLogger();

try
{
logger.Info("Starting up host");
Expand Down
15 changes: 15 additions & 0 deletions src/SFA.DAS.Notifications.Api/nlog.Development.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<extensions>
<add assembly="SFA.DAS.NLog.Targets.Redis" />
</extensions>
<variable name="appName" value="das-notifications-api" />
<variable name="simplelayout" value="${longdate} [${uppercase:${level}}] [${logger}] - ${message} ${onexception:${exception:format=tostring}}" />
<targets>
<target name="Console" layout="${simplelayout}" xsi:type="Console" />
<target name="File" fileName="${basedir}/logs/${appName}.${shortdate}.log" layout="${simplelayout}" xsi:type="File" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="File" />
</rules>
</nlog>
3 changes: 1 addition & 2 deletions src/SFA.DAS.Notifications.Api/nlog.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
<variable name="simplelayout" value="${longdate} [${uppercase:${level}}] [${logger}] - ${message} ${onexception:${exception:format=tostring}}" />
<targets>
<target name="Console" layout="${simplelayout}" xsi:type="Console" />
<target name="File" fileName="${basedir}/logs/${appName}.${shortdate}.log" layout="${simplelayout}" xsi:type="File" />
<target name="Redis" appName="${appName}" environmentKeyName="EnvironmentName" connectionStringName="LoggingRedisConnectionString" includeAllProperties="true" layout="${message}" xsi:type="Redis" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="File, Redis" />
<logger name="*" minlevel="Info" writeTo="Redis" />
</rules>
</nlog>
2 changes: 1 addition & 1 deletion src/SFA.DAS.Notifications.MessageHandlers/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static async Task Main(string[] args)
.ConfigureDasAppConfiguration(args)
.ConfigureLogging((context, b) =>
{
b.AddNLog();
b.AddNLog(context.HostingEnvironment.IsDevelopment() ? "nlog.development.config" : "nlog.config");
b.AddApplicationInsightsWebJobs(o => o.InstrumentationKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]);
})
.UseConsoleLifetime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="nlog.Development.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
15 changes: 15 additions & 0 deletions src/SFA.DAS.Notifications.MessageHandlers/nlog.Development.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<extensions>
<add assembly="SFA.DAS.NLog.Targets.Redis" />
</extensions>
<variable name="appName" value="das-notifications-worker"/>
<variable name="simplelayout" value="${longdate} [${uppercase:${level}}] [${logger}] - ${message} ${onexception:${exception:format=tostring}}" />
<targets>
<target name="Console" layout="${simplelayout}" xsi:type="Console" />
<target name="File" fileName="${basedir}/logs/${appName}.${shortdate}.log" layout="${simplelayout}" xsi:type="File" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="Console, File" />
</rules>
</nlog>
3 changes: 1 addition & 2 deletions src/SFA.DAS.Notifications.MessageHandlers/nlog.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
<variable name="simplelayout" value="${longdate} [${uppercase:${level}}] [${logger}] - ${message} ${onexception:${exception:format=tostring}}" />
<targets>
<target name="Console" layout="${simplelayout}" xsi:type="Console" />
<target name="File" fileName="${basedir}/logs/${appName}.${shortdate}.log" layout="${simplelayout}" xsi:type="File" />
<target name="Redis" appName="${appName}" environmentKeyName="EnvironmentName" connectionStringName="APPSETTING_LoggingRedisConnectionString" includeAllProperties="true" layout="${message}" xsi:type="Redis" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="Console, File, Redis" />
<logger name="*" minlevel="Debug" writeTo="Console, Redis" />
</rules>
</nlog>

0 comments on commit d43a259

Please sign in to comment.