.NET Logging adaptors
Перейти к файлу
Dmitry-Matveev c00c19c488 Update to Base SDK 2.9.1 2019-02-06 16:20:48 -08:00
HelloWorldTest Merge branch 'develop' into tilee/update_dependencies 2018-06-28 09:36:14 -07:00
SDL sdl script revision (#142) 2018-01-12 10:50:16 -08:00
src Update to Base SDK 2.9.1 2019-02-06 16:20:48 -08:00
test Update to Base SDK 2.9.1 2019-02-06 16:20:48 -08:00
.gitattributes fix stylecop (#117) 2017-09-01 21:09:57 -07:00
.gitignore Initial commit 2015-11-12 21:13:46 -08:00
35MSSharedLib1024.snk Initial commit 2015-11-12 21:13:46 -08:00
AddXmlLanguage.targets Add Xml Doc back to Nuget Packages 2018-07-25 14:02:37 -07:00
ApplicationInsightsSDKRules.ruleset disable fxcop "Identifiers should not match keywords" (#217) 2018-09-13 13:42:20 -07:00
CHANGELOG.md Update to Base SDK 2.9.1 2019-02-06 16:20:48 -08:00
CodeCov.ps1 revert bad edit of codecov.ps1 (#136) 2018-02-07 10:02:28 -08:00
Common.props Fix fxcop running on netstandard2.0 and failing 2018-12-31 11:17:22 -08:00
Common.targets Added injection of language into XML documentation files. 2016-09-08 11:44:21 -07:00
Directory.Build.props 4 of many... convert two more projects to generate it's own package (#133) 2017-11-21 10:35:31 -08:00
EnlistmentRoot.marker Initial commit 2015-11-12 21:13:46 -08:00
GenerateReleaseMetadata.ps1 new script: GenerateReleaseMetadata (#170) 2018-04-11 15:47:50 -07:00
GlobalStaticVersion.props Update to Base SDK 2.9.1 2019-02-06 16:20:48 -08:00
LICENSE License and Documentation 2015-11-13 10:50:44 -08:00
Logging.sln Adding unit tests and shifting from using TelemetryConfiguration to IOptions<TelemetryConfiguration> 2018-12-18 10:24:46 -08:00
Microsoft-Security-Recommended.ruleset Added rules and enabled code analysis on build. 2016-08-11 19:55:35 -07:00
NuGet.Config Add myget feed to nuget.config 2019-01-02 10:41:54 -08:00
NuGet.exe add script to audit nupkg during build (#223) 2018-10-08 16:34:11 -07:00
NugetAudit.ps1 LicenseUrl to LicenseExpression 2019-01-29 12:16:33 -08:00
PushNugetPackages.cmd Initial commit 2015-11-12 21:13:46 -08:00
README.md cleanup 2019-01-30 08:58:33 -08:00
Signing.targets Initial commit 2015-11-12 21:13:46 -08:00
Test.props Switched from stelycop msbuild to stelycop analyzer (#125) 2017-11-10 00:15:10 -08:00
ThirdPartyNotices.txt Adding third party notices 2016-09-07 15:41:31 -07:00
VSOPushNugetPackages.cmd Update nuget package path 2016-01-22 08:54:25 -08:00
buildDebug.cmd Migrate EventSourceListener project to netstandard1.3 2017-03-29 17:39:46 -07:00
buildRelease.cmd Migrate EventSourceListener project to netstandard1.3 2017-03-29 17:39:46 -07:00
clean.cmd Tilee/fix unittests2 (#146) 2018-02-09 13:16:03 -08:00
dirs.proj Migrate EventSourceListener project to netstandard1.3 2017-03-29 17:39:46 -07:00
disablestrongnamevalidation.ps1 Added ps scripts to enable disable strong name verification. This is needed to run tests in the build infra. 2017-08-10 15:21:33 -07:00
enablestrongnamevalidation.ps1 Added ps scripts to enable disable strong name verification. This is needed to run tests in the build infra. 2017-08-10 15:21:33 -07:00

README.md

Build codecov.io

Nuget packages

Application Insights logging adapters.

If you use NLog, log4Net or System.Diagnostics.Trace for diagnostic tracing in your application, you can have your logs sent to Application Insights, where you can explore and search them. Your logs will be merged with the other telemetry coming from your application, so that you can identify the traces associated with servicing each user request, and correlate them with other events and exception reports.

Read more:

ILogger

See this.

NLog

Application Insights NLog Target nuget package adds ApplicationInsights target in your web.config (If you use application type that does not have web.config you can install the package but you need to configure ApplicationInsights programmatically; see below).

For more information, see NLog Documentation

  • If you configure NLog though web config then you just need do the following:
// You need this only if you did not define InstrumentationKey in ApplicationInsights.config
TelemetryConfiguration.Active.InstrumentationKey = "Your_Resource_Key";

Logger logger = LogManager.GetLogger("Example");

logger.Trace("trace log message");
  • If you configure NLog programmatically than create Application Insights target in code and add it to your other targets:
var config = new LoggingConfiguration();

ApplicationInsightsTarget target = new ApplicationInsightsTarget();
// You need this only if you did not define InstrumentationKey in ApplicationInsights.config or want to use different instrumentation key
target.InstrumentationKey = "Your_Resource_Key";

LoggingRule rule = new LoggingRule("*", LogLevel.Trace, target);
config.LoggingRules.Add(rule);

LogManager.Configuration = config;

Logger logger = LogManager.GetLogger("Example");

logger.Trace("trace log message");

Log4Net

Application Insights Log4Net adapter nuget modifies web.config and adds Application Insights Appender.

For more information, see Log4Net Configuration

// You do not need this if you have instrumentation key in the ApplicationInsights.config
TelemetryConfiguration.Active.InstrumentationKey = "Your_Resource_Key";

log4net.Config.XmlConfigurator.Configure();
var logger = LogManager.GetLogger(this.GetType());

logger.Info("Message");
logger.Warn("A warning message");
logger.Error("An error message");

System.Diagnostics

Microsoft.ApplicationInsights.TraceListener nuget package modifies web.config and adds application insights listener.

For more information, see "Microsoft Docs: "Tracing and Instrumenting Applications"

<configuration>
  <system.diagnostics>
    <trace>
      <listeners>
        <add name="myAppInsightsListener" type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

If your application type does not have web.config, add listener programmatically or in the configuration file appropriate to your application type

// You do not need this if you have instrumentation key in the ApplicationInsights.config
TelemetryConfiguration.Active.InstrumentationKey = "Your_Resource_Key";
System.Diagnostics.Trace.TraceWarning("Slow response - database01");

EventSource

EventSourceTelemetryModule allows you to configure EventSource events to be sent to Application Insights as traces.

For more information, see Microsoft Docs: "Using EventSource Events".

ETW

EtwCollectorTelemetryModule allows you to configure events from ETW providers to be sent to Application Insights as traces.

For more information, see Microsoft Docs: "Using ETW Events".

DiagnosticSource

You can configure System.Diagnostics.DiagnosticSource events to be sent to Application Insights as traces.

For more information, see CoreFX: "Diagnostic Source Users Guide".

To enable, edit the TelemetryModules section of the ApplicationInsights.config file:

<Add Type="Microsoft.ApplicationInsights.DiagnsoticSourceListener.DiagnosticSourceTelemetryModule, Microsoft.ApplicationInsights.DiagnosticSourceListener">
      <Sources>
        <Add Name="MyDiagnosticSourceName" />
      </Sources>
 </Add>