Created
January 25, 2019 11:50
-
-
Save danielplawgo/6a0a19a903120b66a89138039902af28 to your computer and use it in GitHub Desktop.
Grupowanie wiadomości w nLogu w ramach żądania HTTP
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
public class HomeController : Controller | |
{ | |
private static ILogger _logger = NLog.LogManager.GetCurrentClassLogger(); | |
public ActionResult Index() | |
{ | |
_logger.Info("Home.Index started."); | |
Random random = new Random(); | |
var value = random.Next(1, 3); | |
_logger.Info($"Home.Index value is equal {value}"); | |
if (value == 1) | |
{ | |
_logger.Error("Error during processing value"); | |
throw new Exception("Error during processing value"); | |
} | |
_logger.Info("Home.Index ended."); | |
return View(); | |
} | |
} |
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
2019-01-25 06:15:23.7035 INFO Home.Index started. | |
2019-01-25 06:15:23.7074 INFO Home.Index value is equal 2 | |
2019-01-25 06:15:23.7074 INFO Home.Index ended. | |
2019-01-25 06:15:23.7035 INFO Home.Index started. | |
2019-01-25 06:15:23.7035 INFO Home.Index started. | |
2019-01-25 06:15:23.7074 INFO Home.Index value is equal 2 | |
2019-01-25 06:15:23.7035 INFO Home.Index started. | |
2019-01-25 06:15:23.7035 INFO Home.Index started. | |
2019-01-25 06:15:23.7074 INFO Home.Index value is equal 2 | |
2019-01-25 06:15:23.7204 INFO Home.Index ended. | |
2019-01-25 06:15:23.7074 INFO Home.Index ended. | |
2019-01-25 06:15:23.7204 INFO Home.Index value is equal 1 | |
2019-01-25 06:15:23.7204 ERROR Error during processing value | |
2019-01-25 06:15:23.7074 INFO Home.Index value is equal 2 | |
2019-01-25 06:15:23.7384 INFO Home.Index ended. |
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
2019-01-25 06:15:23.7035 INFO dc6f3750-87a3-41e5-ac56-d9f3453c6581 Home.Index started. | |
2019-01-25 06:15:23.7074 INFO dc6f3750-87a3-41e5-ac56-d9f3453c6581 Home.Index value is equal 2 | |
2019-01-25 06:15:23.7074 INFO dc6f3750-87a3-41e5-ac56-d9f3453c6581 Home.Index ended. | |
2019-01-25 06:15:23.7035 INFO 8415583f-c228-4e2e-b5b7-54a568e18f9e Home.Index started. | |
2019-01-25 06:15:23.7035 INFO 04eaaa85-d320-4e52-9788-0d1aeeab7072 Home.Index started. | |
2019-01-25 06:15:23.7074 INFO 04eaaa85-d320-4e52-9788-0d1aeeab7072 Home.Index value is equal 2 | |
2019-01-25 06:15:23.7035 INFO 52434052-da54-4b34-a800-8c1dc73ccdf4 Home.Index started. | |
2019-01-25 06:15:23.7035 INFO 5ffff241-29db-4101-a4df-c3cb4e74dd73 Home.Index started. | |
2019-01-25 06:15:23.7074 INFO 8415583f-c228-4e2e-b5b7-54a568e18f9e Home.Index value is equal 2 | |
2019-01-25 06:15:23.7204 INFO 8415583f-c228-4e2e-b5b7-54a568e18f9e Home.Index ended. | |
2019-01-25 06:15:23.7074 INFO 04eaaa85-d320-4e52-9788-0d1aeeab7072 Home.Index ended. | |
2019-01-25 06:15:23.7204 INFO 5ffff241-29db-4101-a4df-c3cb4e74dd73 Home.Index value is equal 1 | |
2019-01-25 06:15:23.7204 ERROR 5ffff241-29db-4101-a4df-c3cb4e74dd73 Error during processing value | |
2019-01-25 06:15:23.7074 INFO 52434052-da54-4b34-a800-8c1dc73ccdf4 Home.Index value is equal 2 | |
2019-01-25 06:15:23.7384 INFO 52434052-da54-4b34-a800-8c1dc73ccdf4 Home.Index ended. |
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
public class MvcApplication : System.Web.HttpApplication | |
{ | |
protected void Application_Start() | |
{ | |
AreaRegistration.RegisterAllAreas(); | |
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); | |
RouteConfig.RegisterRoutes(RouteTable.Routes); | |
BundleConfig.RegisterBundles(BundleTable.Bundles); | |
} | |
protected void Application_BeginRequest(object sender, EventArgs e) | |
{ | |
Trace.CorrelationManager.ActivityId = Guid.NewGuid(); | |
} | |
} |
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:\temp\nlog-internal.log"> | |
<targets> | |
<target xsi:type="File" name="f" fileName="${basedir}/App_Data/logs/${shortdate}.log" | |
layout="${longdate} ${uppercase:${level}} ${activityid} ${message}" /> | |
</targets> | |
<rules> | |
<logger name="*" minlevel="Debug" writeTo="f" /> | |
</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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int instances = 5; | |
var tasks = new Task[instances]; | |
for (int i = 0; i < instances; i++) | |
{ | |
tasks[i] = Test(); | |
} | |
Task.WaitAll(tasks); | |
} | |
static Task Test() | |
{ | |
var webClient = new WebClient(); | |
return webClient.DownloadStringTaskAsync("http://localhost:55405/"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment