Created
May 29, 2016 22:06
-
-
Save gravity00/c9384f07f389f0ce25819ee0e3aaa853 to your computer and use it in GitHub Desktop.
Console Application using NLog as the logging framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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" | |
| xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" | |
| autoReload="true" | |
| throwExceptions="false" | |
| internalLogLevel="Off" internalLogFile="C:\Windows\Temp\ConsoleApplication\nlog-internal.log" > | |
| <time type="FastUTC" /> | |
| <targets> | |
| <target name="file" xsi:type="File" | |
| fileName="${basedir}/Logs/${shortdate}.log" | |
| layout="[${longdate}] [${uppercase:${level}}] [${logger}] ${message} ${exception:format=tostring}" | |
| concurrentWrites="false" keepFileOpen="false"/> | |
| <target name="console" xsi:type="ColoredConsole" | |
| layout="[${longdate}] [${uppercase:${level}}] [${logger:shortName=true}] ${message} ${exception:format=tostring}" /> | |
| </targets> | |
| <rules> | |
| <logger name="*" writeTo="console,file" /> | |
| </rules> | |
| </nlog> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <packages> | |
| <package id="NLog" version="4.3.4" targetFramework="net45" /> | |
| <package id="NLog.Config" version="4.3.4" targetFramework="net45" /> | |
| <package id="NLog.Schema" version="4.3.4" targetFramework="net45" /> | |
| </packages> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace ConsoleApplication | |
| { | |
| using System; | |
| using NLog; | |
| public static class Program | |
| { | |
| private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); | |
| public static void Main(string[] args) | |
| { | |
| try | |
| { | |
| Logger.Info("Application started..."); | |
| // run your code here | |
| } | |
| catch (Exception e) | |
| { | |
| Logger.Fatal(e, "An unexpected exception has occured"); | |
| } | |
| finally | |
| { | |
| Logger.Info("Application terminated. Press <enter> to exit..."); | |
| Console.ReadLine(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment