Skip to content

Upgrading NLog 4 to 5

Breaking4.7.15 → 5.5.1Breaking3Deprecated20New45Changed122Fixed57Other29

BreakingUpgrade verdict

3 breaking changes.

  • Types no longer carry the Serializable attribute or support SerializationInfo-based serialization, which .NET 8 marks obsolete.
  • Removes the irrelevant StructuredMessageTemplateAttribute from ILogger.
  • The shorthand name DB for the database target has been removed, so configurations using it must switch to the full name.
  • The RegisterType method on IFactory is deprecated and will be removed in NLog 6.
Top 5 of 23 that need code or config changes

Target frameworks requirement changed in 5.0.0-preview.1: .NETFramework3.5, .NETFramework4.0-Client, .NETFramework4.5, .NETStandard1.3, .NETStandard1.5, .NETStandard2.0, MonoAndroid4.4, Silverlight4.0, Silverlight5.0, WindowsPhone8.0, Xamarin.iOS1.0 → .NETFramework3.5, .NETFramework4.5, .NETFramework4.6, .NETStandard1.3, .NETStandard1.5, .NETStandard2.0.

Adds system.net.http 4.3.4, system.text.regularexpressions 4.3.1.

Drops microsoft.extensions.platformabstractions.

Breaking3
Removes the Serializable attribute and SerializationInfo support since they are obsolete in NET8.
SerializableSerializationInfo
Removes the irrelevant StructuredMessageTemplateAttribute from ILogger.
ILoggerStructuredMessageTemplateAttribute
Removes the DB alias from DatabaseTarget to avoid promoting acronyms.
DatabaseTargetDB
Deprecated20
Marks IFactory RegisterType as obsolete, since it will be removed with NLog v6.
IFactoryRegisterType
Marks JsonLayout EscapeForwardSlash as obsolete, since disabled with NLog v6.
JsonLayoutEscapeForwardSlash
Marks ExceptionLayoutRenderer Formats-List as obsolete, since immutable with NLog v6.
ExceptionLayoutRendererFormats
Marks JsonLayout EscapeForwardSlash as obsolete.
JsonLayoutEscapeForwardSlash
Marks NLogViewerTarget and IncludeNLogData as obsolete.
NLogViewerTargetIncludeNLogData
Marks XmlLoggingConfiguration AppConfig as obsolete.
XmlLoggingConfigurationAppConfig
Marks XmlLoggingConfiguration InitializeSucceeded as obsolete.
XmlLoggingConfigurationInitializeSucceeded
Marks LogEventInfo SetStackTrace with UserStackFrameNumber as obsolete.
LogEventInfoSetStackTraceUserStackFrameNumber
Marks SetupFromEnvironmentVariables and LogToTrace as obsolete.
SetupFromEnvironmentVariablesLogToTrace
LogManager AddHiddenAssembly is marked obsolete; use AddCallSiteHiddenAssembly instead.
LogManager.AddHiddenAssemblyAddCallSiteHiddenAssembly
InternalLogger LogToTrace is marked obsolete to reduce dependencies.
InternalLogger.LogToTrace
ILoggerBase and ISuppress are marked obsolete; use ILogger instead.
ILoggerBaseISuppressILogger
LoggingRule ChildRules is marked obsolete.
LoggingRule.ChildRules
FileTarget NetworkWrites is marked obsolete and replaced by KeepFileOpen=false.
FileTarget.NetworkWritesKeepFileOpen
EscapeDataNLogLegacy is marked obsolete.
EscapeDataNLogLegacy
Updates the obsolete warning for the ConfigurationReloaded event.
ConfigurationReloaded
Updates the obsolete warning for the ErrorException method and related methods.
ILoggerErrorException
Marks Target LayoutWithLock as obsolete since it is only a temporary workaround.
Target.LayoutWithLock
Marks NLogRuntimeException constructor with string.Format as obsolete.
NLogRuntimeException
Marks the NLogConfigurationException constructor that takes a string.Format format and arguments as obsolete.
NLogConfigurationException