From f825a318bb5945aab42e9e15eb4edd3e7857abed Mon Sep 17 00:00:00 2001 From: Shweta Jain Date: Fri, 13 Apr 2018 17:16:53 +0530 Subject: [PATCH 1/4] Instrunctions for .NETCore2.0 --- README.md | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/README.md b/README.md index 01f6a7a..7220e37 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ log4net-loggly Custom log4net appenders for importing logging events to loggly. It’s asynchronous and will send logs in the background without blocking your application. Check out Loggly's [.Net logging documentation](https://www.loggly.com/docs/net-logs/) to learn more. +Note: This library also has a support for .NET Core applications. Please see the section .NET Core Support below. + Download log4net-loggly package from NuGet. Use the following command. Install-Package log4net-loggly @@ -76,6 +78,84 @@ You should add the following statement at the end of your Main method as the log ``` Console.ReadKey(); ``` +.NET Core Support: + +Prerequisites: + +- Since this library support .NET Core target framework 2.0, make sure you are using version 15.3.0 or higher of Visual Studio IDE 2017. + +- You must have installed the .NET Core 2.0 SDK and Runtime environment. + +- You may also have to install the .NET Core cross-platform development workload (in the Other Toolsets section). Please see the more details [here](https://docs.microsoft.com/en-us/dotnet/core/windows-prerequisites?tabs=netcore2x). + +Once you are done with the environment setup, now you are all set to create your application in .NET Core target framework 2.0. Please follow the points below- + +- You have to install the package log4net-loggly as shown below- + +``` +Install-Package log4net-loggly +``` + +- Now when you create an applicaton in .NET Core, there is no App.config file exist already in the project so you have to create one. Right click on your project and create a Application Configuration File "App.config" on the root level of your project. + +- You should simply add the below configuration code in your App.config file to configure LogglyAppender in your application. Make sure the configSections block is the first element of the configuration in app.config. This is a requirement set by .NET. + +``` + +
+ + + + + + + + + + + + + + +``` + +Note: Your application will not be able to read configurations from this App.config file until you do the following- + +- Right click on your App.config file from Solution Explorer, go to Properties and select the Copy to Output Directory to Copy always, click Apply and hit the OK button. + +- As compare to .NET Frameworks, in .NET Core you don't need any AssemblyInfo.cs file to add the below code in- + +``` +[assembly: log4net.Config.XmlConfigurator(Watch = true)] +``` + +The above code line allows the application to read the configuration from App.config file. In .NET Core applications, we will be reading the configuartions in a different way which is stated below- + +- Add the following code inside the main method of your application file i.e. Program.cs- + +``` +var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); +log4net.Config.XmlConfigurator.Configure(logRepository, new FileInfo("App.config")); +``` +After adding the above code you can simply create an object of the Log class using LogManager and start logging any plaintext, exceptions, or JSON events as shown below- + +``` +var logger = LogManager.GetLogger(typeof(Class)); +//Send plaintext +logger.Info("your log message"); + +//Send an exception +logger.Error("your log message", new Exception("your exception message")); + +//Send a JSON object +var items = new Dictionary(); +items.Add("key1","value1"); +items.Add("key2", "value2"); +logger.Info(items); +``` + +And that's it. After doing this, you will see your .NET Core application logs flowing into Loggly. + Added handling for LoggingEvent properties From 45669755fca0aa4cc1f5a534d7d2ba7505502b25 Mon Sep 17 00:00:00 2001 From: Shweta Jain Date: Mon, 16 Apr 2018 15:17:41 +0530 Subject: [PATCH 2/4] Add instructions for VS Code users --- README.md | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7220e37..18dcb6a 100644 --- a/README.md +++ b/README.md @@ -82,21 +82,41 @@ Console.ReadKey(); Prerequisites: -- Since this library support .NET Core target framework 2.0, make sure you are using version 15.3.0 or higher of Visual Studio IDE 2017. +- Since this library support .NET Core target framework 2.0, make sure you are using either version 15.3.0 or higher of Visual Studio IDE 2017 or Visual Studio Code. -- You must have installed the .NET Core 2.0 SDK and Runtime environment. +- You must have installed the .NET Core 2.0 SDK and Runtime environment to develop and run your .NET Core 2.0 applications. - You may also have to install the .NET Core cross-platform development workload (in the Other Toolsets section). Please see the more details [here](https://docs.microsoft.com/en-us/dotnet/core/windows-prerequisites?tabs=netcore2x). Once you are done with the environment setup, now you are all set to create your application in .NET Core target framework 2.0. Please follow the points below- -- You have to install the package log4net-loggly as shown below- +- If you are using Visual Studio 2017 IDE then you can create a new .NET Core project by selecting New Project from File menu. + +- Visual Studio Code users can create a new project by running the below command on the project workspace terminal- + +``` +dotnet new console -o Application_Name +``` + +The dotnet command creates a new application of type console for you. The -o parameter creates a directory named where your app is stored, and populates it with the required files. + +- You have to install the package log4net-loggly into your project from NuGet by running the command on Package Manager Console as shown below- ``` Install-Package log4net-loggly ``` -- Now when you create an applicaton in .NET Core, there is no App.config file exist already in the project so you have to create one. Right click on your project and create a Application Configuration File "App.config" on the root level of your project. +- If you are using Visual Studio Code then run the below command on the terminal to install the log4net-loggly package. + +``` +dotnet add package log4net-loggly +``` + +- Now when you create an applicaton in .NET Core, there is no App.config file exist already in the project so you have to create one. + + (a) For Visual Studio 2017 users, you should right click on your project and create a Application Configuration File "App.config" on the root level of your project. + + (b) For Visual Studio Code users, you should simply create the same configuration file on the the folder structure where your another files exists. - You should simply add the below configuration code in your App.config file to configure LogglyAppender in your application. Make sure the configSections block is the first element of the configuration in app.config. This is a requirement set by .NET. @@ -119,10 +139,12 @@ Install-Package log4net-loggly ``` -Note: Your application will not be able to read configurations from this App.config file until you do the following- +Note: If you are using Visual Studio 2017 IDE then your application will not be able to read configurations from this App.config file until you do the following- - Right click on your App.config file from Solution Explorer, go to Properties and select the Copy to Output Directory to Copy always, click Apply and hit the OK button. + If you are using Visual Studio Code then you don't need to do the extra settings for App.config file. + - As compare to .NET Frameworks, in .NET Core you don't need any AssemblyInfo.cs file to add the below code in- ``` @@ -154,6 +176,14 @@ items.Add("key2", "value2"); logger.Info(items); ``` +Running the application in Visual Studio 2017 IDE is easy since you just need to click on the Start button to run your application. + +If you are using Visual Studio Code then you have to run the below command on the terminal to run your .NET Core application- + +``` +dotnet run +``` + And that's it. After doing this, you will see your .NET Core application logs flowing into Loggly. From 154af30ae48a1b0abb4b6684c28b9bb6cc0876dc Mon Sep 17 00:00:00 2001 From: Shwetajain148 Date: Mon, 16 Apr 2018 17:47:08 +0530 Subject: [PATCH 3/4] Update --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 18dcb6a..f8c031d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ log4net-loggly Custom log4net appenders for importing logging events to loggly. It’s asynchronous and will send logs in the background without blocking your application. Check out Loggly's [.Net logging documentation](https://www.loggly.com/docs/net-logs/) to learn more. -Note: This library also has a support for .NET Core applications. Please see the section .NET Core Support below. +Note: This library also has a support for .NET Core applications. Please see the section [.NET Core Support](https://github.com/Shwetajain148/log4net-loggly/blob/update-instrunctions-for-dotnetcore/README.md#net-core-support) below. Download log4net-loggly package from NuGet. Use the following command. @@ -78,7 +78,7 @@ You should add the following statement at the end of your Main method as the log ``` Console.ReadKey(); ``` -.NET Core Support: +### .NET Core Support: Prerequisites: @@ -100,13 +100,13 @@ dotnet new console -o Application_Name The dotnet command creates a new application of type console for you. The -o parameter creates a directory named where your app is stored, and populates it with the required files. -- You have to install the package log4net-loggly into your project from NuGet by running the command on Package Manager Console as shown below- +- If you are using Visual Studio 2017 IDE then you have to install the package log4net-loggly into your project from NuGet by running the command on Package Manager Console as shown below- ``` Install-Package log4net-loggly ``` -- If you are using Visual Studio Code then run the below command on the terminal to install the log4net-loggly package. +- If you are using Visual Studio Code then run the below command on the terminal to install the log4net-loggly package. ``` dotnet add package log4net-loggly From 5f6f6180d0a919d5bef31bcc18ed8b13c3103be7 Mon Sep 17 00:00:00 2001 From: Shwetajain148 Date: Mon, 16 Apr 2018 17:58:05 +0530 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f8c031d..bab1ca5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ log4net-loggly Custom log4net appenders for importing logging events to loggly. It’s asynchronous and will send logs in the background without blocking your application. Check out Loggly's [.Net logging documentation](https://www.loggly.com/docs/net-logs/) to learn more. -Note: This library also has a support for .NET Core applications. Please see the section [.NET Core Support](https://github.com/Shwetajain148/log4net-loggly/blob/update-instrunctions-for-dotnetcore/README.md#net-core-support) below. +Note: This library also has a support for .NET Core applications. Please see the section [.NET Core Support](README.md#net-core-support) below. Download log4net-loggly package from NuGet. Use the following command.