Skip to content

Commit 872537a

Browse files
committed
Fixed NLog 5.0 upgrade warnings
1 parent 9a7ee3e commit 872537a

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

src/Platforms/Exceptionless.NLog/ExceptionlessTarget.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using NLog;
4-
using NLog.Common;
54
using NLog.Config;
65
using NLog.Targets;
76

src/Platforms/Exceptionless.NLog/LogBuilderExtensions.cs renamed to src/Platforms/Exceptionless.NLog/LogEventBuilderExtensions.cs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,27 @@
33
using Exceptionless.Models;
44
using Exceptionless.Models.Data;
55
using NLog;
6-
using NLog.Fluent;
76

87
namespace Exceptionless.NLog {
9-
public static class LogBuilderExtensions {
8+
public static class LogEventBuilderExtensions {
9+
/// <summary>
10+
/// Sets the logger name of the logging event.
11+
/// </summary>
12+
/// <param name="builder">The log builder object.</param>
13+
/// <param name="loggerName">The logger name of the logging event.</param>
14+
/// <returns>current <see cref="LogEventBuilder"/> for chaining calls.</returns>
15+
internal static LogEventBuilder LoggerName(this LogEventBuilder builder, string loggerName = null) {
16+
if (builder.LogEvent != null)
17+
builder.LogEvent.LoggerName = loggerName;
18+
19+
return builder;
20+
}
21+
1022
/// <summary>
1123
/// Marks the event as being a critical occurrence.
1224
/// </summary>
13-
public static LogBuilder Critical(this LogBuilder builder, bool isCritical = true) {
25+
[CLSCompliant(false)]
26+
public static LogEventBuilder Critical(this LogEventBuilder builder, bool isCritical = true) {
1427
return isCritical ? builder.Tag("Critical") : builder;
1528
}
1629

@@ -19,8 +32,11 @@ public static LogBuilder Critical(this LogBuilder builder, bool isCritical = tru
1932
/// </summary>
2033
/// <param name="builder">The log builder object.</param>
2134
/// <param name="tags">The tags to be added to the event.</param>
22-
public static LogBuilder Tag(this LogBuilder builder, params string[] tags) {
23-
builder.LogEventInfo.AddTags(tags);
35+
[CLSCompliant(false)]
36+
public static LogEventBuilder Tag(this LogEventBuilder builder, params string[] tags) {
37+
if (builder.LogEvent != null)
38+
builder.LogEvent.AddTags(tags);
39+
2440
return builder;
2541
}
2642

@@ -29,7 +45,8 @@ public static LogBuilder Tag(this LogBuilder builder, params string[] tags) {
2945
/// </summary>
3046
/// <param name="builder">The log builder object.</param>
3147
/// <param name="identity">The user's identity that the event happened to.</param>
32-
public static LogBuilder Identity(this LogBuilder builder, string identity) {
48+
[CLSCompliant(false)]
49+
public static LogEventBuilder Identity(this LogEventBuilder builder, string identity) {
3350
return builder.Identity(identity, null);
3451
}
3552

@@ -39,15 +56,18 @@ public static LogBuilder Identity(this LogBuilder builder, string identity) {
3956
/// <param name="builder">The log builder object.</param>
4057
/// <param name="identity">The user's identity that the event happened to.</param>
4158
/// <param name="name">The user's friendly name that the event happened to.</param>
42-
public static LogBuilder Identity(this LogBuilder builder, string identity, string name) {
59+
[CLSCompliant(false)]
60+
public static LogEventBuilder Identity(this LogEventBuilder builder, string identity, string name) {
4361
if (String.IsNullOrWhiteSpace(identity) && String.IsNullOrWhiteSpace(name))
4462
return builder;
4563

4664
return builder.Property(Event.KnownDataKeys.UserInfo, new UserInfo(identity, name));
4765
}
4866

49-
public static LogBuilder ContextProperty(this LogBuilder builder, string key, object value) {
50-
builder.LogEventInfo.SetContextDataProperty(key, value);
67+
[CLSCompliant(false)]
68+
public static LogEventBuilder ContextProperty(this LogEventBuilder builder, string key, object value) {
69+
if (builder.LogEvent != null)
70+
builder.LogEvent.SetContextDataProperty(key, value);
5171

5272
return builder;
5373
}
@@ -57,10 +77,14 @@ public static LogBuilder ContextProperty(this LogBuilder builder, string key, ob
5777
/// </summary>
5878
/// <param name="builder">The log builder object.</param>
5979
/// <param name="submissionMethod">The submission method.</param>
60-
public static LogBuilder MarkUnhandled(this LogBuilder builder, string submissionMethod = null) {
61-
builder.LogEventInfo.SetContextDataProperty(IsUnhandledError, true);
80+
[CLSCompliant(false)]
81+
public static LogEventBuilder MarkUnhandled(this LogEventBuilder builder, string submissionMethod = null) {
82+
if (builder.LogEvent != null)
83+
return builder;
84+
85+
builder.LogEvent.SetContextDataProperty(IsUnhandledError, true);
6286
if (!String.IsNullOrEmpty(submissionMethod))
63-
builder.LogEventInfo.SetContextDataProperty(SubmissionMethod, submissionMethod);
87+
builder.LogEvent.SetContextDataProperty(SubmissionMethod, submissionMethod);
6488

6589
return builder;
6690
}

src/Platforms/Exceptionless.NLog/NLogExceptionlessLog.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,36 @@ public NLogExceptionlessLog(LogLevel minimumLogLevel = null) {
1818
public void Error(string message, string source = null, Exception exception = null) {
1919
if (LogLevel.Error < MinimumLogLevel)
2020
return;
21-
22-
_logger.Error().Message(message).LoggerName(source).Exception(exception).Write();
21+
22+
_logger.ForErrorEvent().Message(message).LoggerName(source).Log();
2323
}
2424

2525
public void Info(string message, string source = null) {
2626
if (LogLevel.Info < MinimumLogLevel)
2727
return;
28-
29-
_logger.Info().Message(message).LoggerName(source).Write();
28+
29+
_logger.ForInfoEvent().Message(message).LoggerName(source).Log();
3030
}
3131

3232
public void Debug(string message, string source = null) {
3333
if (LogLevel.Debug < MinimumLogLevel)
3434
return;
35-
36-
_logger.Debug().Message(message).LoggerName(source).Write();
35+
36+
_logger.ForDebugEvent().Message(message).LoggerName(source).Log();
3737
}
3838

3939
public void Warn(string message, string source = null) {
4040
if (LogLevel.Warn < MinimumLogLevel)
4141
return;
42-
43-
_logger.Warn().Message(message).LoggerName(source).Write();
42+
43+
_logger.ForWarnEvent().Message(message).LoggerName(source).Log();
4444
}
4545

4646
public void Trace(string message, string source = null) {
4747
if (LogLevel.Trace < MinimumLogLevel)
4848
return;
49-
50-
_logger.Trace().Message(message).LoggerName(source).Write();
49+
50+
_logger.ForTraceEvent().Message(message).LoggerName(source).Log();
5151
}
5252

5353
public void Flush() { }

0 commit comments

Comments
 (0)